home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sompar.zip / PARTS.CPP < prev    next >
C/C++ Source or Header  |  1993-12-19  |  14KB  |  375 lines

  1. //
  2. // Project: Digitalk Parts like Toolbar and SOMObjects Demo
  3. // File:    Parts.cpp
  4. // Author:  Stewart Hyde
  5. // Created: Dec   17, 1993
  6. // Updated: Dec   19, 1993
  7. //
  8. // Description:
  9. //
  10.  
  11. #include <stdlib.h>
  12. #include <icolor.hpp>
  13. #include <ifont.hpp>
  14. #include <istring.hpp>
  15. #include <ireslib.hpp>
  16. #include "somparts.h"
  17. #include "parts.hpp"
  18. #include "setpages.hpp"
  19.  
  20. // ------------------------------------------------------------------------
  21. //  Class:                PartsNoteTool        
  22. //  Function:            PartsNoteTool    (constructor)
  23. //                
  24. //  Description:        This is the contructor for Parts Style Notebook
  25. //       
  26. //  Input:                IWindow *parentWin - parent window
  27. //                            IWindow *ownerWin  - owner window
  28. //
  29. //  Output:                N/A
  30. //
  31. //  Notes:
  32. //
  33. // ------------------------------------------------------------------------
  34.  
  35. PartsNoteTool::PartsNoteTool(IWindow *parentWin, 
  36.                              IWindow *ownerWin,
  37.                                       SomAction *somAction)    
  38.           : INotebook(WND_PARTS_NOTE_BOOK, 
  39.                   parentWin,
  40.                   ownerWin, 
  41.                   IRectangle(),
  42.                   backPagesBottomRight | majorTabsLeft |
  43.                         squareTabs | spiralBinding |
  44.                         tabTextCenter| statusTextCenter)
  45. {
  46.     // ---------------------------------------------------------------------
  47.       // Save pointer to SomActions class
  48.     // ---------------------------------------------------------------------
  49.  
  50.     somAct= somAction;
  51.  
  52.     // ---------------------------------------------------------------------
  53.       // Set the font for the notebook
  54.     // ---------------------------------------------------------------------
  55.  
  56.       IFont font("Helv", 10);
  57.       setFont(font);
  58.   
  59.     // ---------------------------------------------------------------------
  60.       // Set the page button size to be the maximum character height 
  61.     // ---------------------------------------------------------------------
  62.  
  63.       setPageButtonSize(ISize(font.maxCharHeight(),font.maxCharHeight()));
  64.   
  65.   
  66.     // ---------------------------------------------------------------------
  67.       // Set background to pale gray
  68.     // ---------------------------------------------------------------------
  69.  
  70.    setColor(pageBackground, IColor(IColor::paleGray));
  71.   
  72.  
  73.     // ---------------------------------------------------------------------
  74.       // start handling notebook page events
  75.     // ---------------------------------------------------------------------
  76.  
  77.       IPageHandler::handleEventsFor(this);
  78.   
  79.     // ---------------------------------------------------------------------
  80.      // Initialize the notebook pages, this function is use to create the
  81.     // notebook pages, initialize its associated data and size its tabs
  82.     // and sets the note books position and size if necessary
  83.     // ---------------------------------------------------------------------
  84.  
  85.     initNoteBookPages();
  86.  
  87.     // ---------------------------------------------------------------------
  88.       // Size the notebook to its minimum size
  89.     // ---------------------------------------------------------------------
  90.  
  91.       sizeTo(calcMinimumSize());
  92. }
  93.  
  94. // ------------------------------------------------------------------------
  95. //  Class:                  PartsNoteTool
  96. //  Function:            initNoteBookPages
  97. //                
  98. //  Description:        Initialize the notebook pages, this function is use
  99. //                            to create the notebook pages, initialize its associated
  100. //                            data and size its tabs and sets the note books position
  101. //                            and size if necessary
  102. //       
  103. //  Input:                 N/A
  104. //
  105. //  Output:                N/A
  106. //
  107. //  Notes:
  108. //
  109. // ------------------------------------------------------------------------
  110.  
  111. void PartsNoteTool::initNoteBookPages()
  112. {
  113.     INotebook::PageSettings settings;
  114.       IFont font(this);
  115.       int majorLength = 0;
  116.       INotebook::Cursor cursor(*this);
  117.  
  118.  
  119.     // ---------------------------------------------------------------------
  120.    // setup PageSettings for the notebook page for Set #1
  121.     // ---------------------------------------------------------------------
  122.  
  123.    settings = INotebook::PageSettings(INotebook::PageSettings::majorTab |
  124.                                               INotebook::PageSettings::statusTextOn |
  125.                                                   INotebook::PageSettings::autoPageSize);
  126.  
  127.    settings.setStatusText(IResourceId(STR_SET1_PAGE_STATUS));
  128.    settings.setTabText(IResourceId(STR_SET1_PAGE_TAB));
  129.       
  130.     // ---------------------------------------------------------------------
  131.    // add the Set #1 page to the notebook 
  132.     // ---------------------------------------------------------------------
  133.  
  134.    page1 = addLastPage(settings);
  135.       
  136.     {
  137.        // ------------------------------------------------------------------
  138.         //  Create a Set #1 class instance and use it as the window for the 
  139.         //  this page in the notebook
  140.        // ------------------------------------------------------------------
  141.  
  142.        Set1Page *pSet1Page = new Set1Page(this, this, somAct);
  143.  
  144.        // ------------------------------------------------------------------
  145.         //  Let the page window manage its destruction, so set it to
  146.         //  autodelete
  147.        // ------------------------------------------------------------------
  148.  
  149.        pSet1Page->setAutoDeleteObject();
  150.  
  151.        // ------------------------------------------------------------------
  152.        // Set the window background to paleGray
  153.        // ------------------------------------------------------------------
  154.  
  155.        pSet1Page->setColor(pSet1Page->background, IColor(IColor::paleGray));
  156.  
  157.         // ------------------------------------------------------------------
  158.       // Attach the window to the notebook page Set #1
  159.       // ------------------------------------------------------------------
  160.  
  161.           setWindow(page1, pSet1Page);
  162.     }
  163.  
  164.     // ---------------------------------------------------------------------
  165.    // setup PageSettings for the notebook page for Set #2
  166.     // ---------------------------------------------------------------------
  167.  
  168.    settings = INotebook::PageSettings(INotebook::PageSettings::majorTab |
  169.                                               INotebook::PageSettings::statusTextOn |
  170.                                                   INotebook::PageSettings::autoPageSize);
  171.  
  172.    settings.setStatusText(IResourceId(STR_SET2_PAGE_STATUS));
  173.    settings.setTabText(IResourceId(STR_SET2_PAGE_TAB));
  174.       
  175.     // ---------------------------------------------------------------------
  176.    // add the Set #2 page to the notebook 
  177.     // ---------------------------------------------------------------------
  178.  
  179.    page2 = addLastPage(settings);
  180.  
  181.     {      
  182.        // ------------------------------------------------------------------
  183.         //  Create a Set #2 class instance and use it as the window for the 
  184.         //  this page in the notebook
  185.        // ------------------------------------------------------------------
  186.  
  187.        Set2Page *pSet2Page = new Set2Page(this, this, somAct);
  188.  
  189.        // ------------------------------------------------------------------
  190.         //  Let the page window manage its destruction, so set it to
  191.         //  autodelete
  192.        // ------------------------------------------------------------------
  193.  
  194.        pSet2Page->setAutoDeleteObject();
  195.  
  196.        // ------------------------------------------------------------------
  197.        // Set the window background to paleGray
  198.        // ---------------------------------------------------------------------
  199.  
  200.        pSet2Page->setColor(pSet2Page->background, IColor(IColor::paleGray));
  201.  
  202.         // ------------------------------------------------------------------
  203.       // Attach the window to the notebook page Set #2
  204.       // ------------------------------------------------------------------
  205.  
  206.           setWindow(page2, pSet2Page);
  207.     }
  208.  
  209.     // ---------------------------------------------------------------------
  210.    // setup PageSettings for the notebook page for Set #3
  211.     // ---------------------------------------------------------------------
  212.  
  213.    settings = INotebook::PageSettings(INotebook::PageSettings::majorTab |
  214.                                               INotebook::PageSettings::statusTextOn |
  215.                                                   INotebook::PageSettings::autoPageSize);
  216.  
  217.    settings.setStatusText(IResourceId(STR_SET3_PAGE_STATUS));
  218.    settings.setTabText(IResourceId(STR_SET3_PAGE_TAB));
  219.       
  220.     // ---------------------------------------------------------------------
  221.    // add the Set #3 page to the notebook 
  222.     // ---------------------------------------------------------------------
  223.  
  224.    page3 = addLastPage(settings);
  225.     
  226.     {  
  227.        // ------------------------------------------------------------------
  228.         //  Create a Set #3 class instance and use it as the window for the 
  229.         //  this page in the notebook
  230.        // ------------------------------------------------------------------
  231.  
  232.        Set3Page *pSet3Page = new Set3Page(this, this, somAct);
  233.  
  234.        // ------------------------------------------------------------------
  235.         //  Let the page window manage its destruction, so set it to
  236.         //  autodelete
  237.        // ------------------------------------------------------------------
  238.  
  239.        pSet3Page->setAutoDeleteObject();
  240.  
  241.        // ------------------------------------------------------------------
  242.        // Set the window background to paleGray
  243.        // ------------------------------------------------------------------
  244.  
  245.        pSet3Page->setColor(pSet3Page->background, IColor(IColor::paleGray));
  246.  
  247.         // ------------------------------------------------------------------
  248.       // Attach the window to the notebook page Set #3
  249.       // ------------------------------------------------------------------
  250.  
  251.           setWindow(page3, pSet3Page);
  252.     }
  253.  
  254.     // ---------------------------------------------------------------------
  255.    // setup PageSettings for the notebook page for Set #4
  256.     // ---------------------------------------------------------------------
  257.  
  258.    settings = INotebook::PageSettings(INotebook::PageSettings::majorTab |
  259.                                               INotebook::PageSettings::statusTextOn |
  260.                                                   INotebook::PageSettings::autoPageSize);
  261.  
  262.    settings.setStatusText(IResourceId(STR_SET4_PAGE_STATUS));
  263.    settings.setTabText(IResourceId(STR_SET4_PAGE_TAB));
  264.       
  265.     // ---------------------------------------------------------------------
  266.    // add the Set #4 page to the notebook 
  267.     // ---------------------------------------------------------------------
  268.  
  269.    page4 = addLastPage(settings);
  270.       
  271.     {
  272.        // ------------------------------------------------------------------
  273.         //  Create a Set #4 class instance and use it as the window for the 
  274.         //  this page in the notebook
  275.        // ------------------------------------------------------------------
  276.  
  277.        Set4Page *pSet4Page = new Set4Page(this, this, somAct);
  278.  
  279.        // ------------------------------------------------------------------
  280.         //  Let the page window manage its destruction, so set it to
  281.         //  autodelete
  282.        // ------------------------------------------------------------------
  283.  
  284.        pSet4Page->setAutoDeleteObject();
  285.  
  286.        // ------------------------------------------------------------------
  287.        // Set the window background to paleGray
  288.        // ------------------------------------------------------------------
  289.  
  290.        pSet4Page->setColor(pSet4Page->background, IColor(IColor::paleGray));
  291.  
  292.         // ------------------------------------------------------------------
  293.       // Attach the window to the notebook page Set #4
  294.       // ------------------------------------------------------------------
  295.  
  296.           setWindow(page4, pSet4Page);
  297.     }
  298.  
  299.    // ---------------------------------------------------------------------
  300.       // Set the page button size to the maximum character height in notebook
  301.    // ---------------------------------------------------------------------
  302.  
  303.       setPageButtonSize(ISize(font.maxCharHeight(),font.maxCharHeight()));
  304.   
  305.  
  306.    // ---------------------------------------------------------------------
  307.       // traverse the notebook pages to find out long major tag in notebook
  308.    // ---------------------------------------------------------------------
  309.  
  310.       for (cursor.setToFirst(); cursor.isValid(); cursor.setToNext())
  311.       {
  312.         INotebook::PageSettings settings = pageSettings(cursor.current());
  313.         if (settings.isMajorTab())
  314.           majorLength = max(majorLength, settings.tabText().length());
  315.       }
  316.  
  317.    // ---------------------------------------------------------------------
  318.     // use the font size to calculate height for tab
  319.    // ---------------------------------------------------------------------
  320.  
  321.       unsigned long height = font.avgUppercase() +
  322.                          font.internalLeading()*2 +
  323.                          font.maxLowercaseAscender();
  324.  
  325.    // ---------------------------------------------------------------------
  326.     //     Not set the settab to approviate value
  327.    // ---------------------------------------------------------------------
  328.  
  329.       try
  330.       {
  331.         setMajorTabSize(ISize((font.avgCharWidth()+4)*majorLength,
  332.                         height));
  333.       } catch (IAccessError &acc)
  334.       {
  335.       }
  336.  
  337.     // ---------------------------------------------------------------------
  338.       // Size the notebook to its minimum size
  339.     // ---------------------------------------------------------------------
  340.  
  341.       sizeTo(calcMinimumSize());
  342. }
  343.  
  344. // ------------------------------------------------------------------------
  345. //  Class:                 PartsNoteTool
  346. //  Function:            select
  347. //                
  348. //  Description:        Notebook select handler which basically pasts focus
  349. //                            on to the notebook page if page is availabele
  350. //       
  351. //  Input:                IPageSelectEvent &evt - page select even
  352. //
  353. //  Output:                Boolean true if page window is valid
  354. //
  355. //  Notes:
  356. //
  357. // ------------------------------------------------------------------------
  358.  
  359. Boolean PartsNoteTool::select(IPageSelectEvent &evt)
  360. {
  361.       IWindow *pageWindow = window(evt.pageHandle());
  362.  
  363.    // ---------------------------------------------------------------------
  364.     //  If page window is valid, setfocus and return true
  365.    // ---------------------------------------------------------------------
  366.  
  367.       if (pageWindow)
  368.       {    
  369.         pageWindow->setFocus();
  370.          return true;
  371.     }
  372.       else
  373.         return false;
  374. }
  375.