home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pwrgu2.zip / POWERGU2.EXE / CANVAS / COMPLEX / XCANVAS.CPP < prev    next >
Text File  |  1995-08-21  |  9KB  |  248 lines

  1. //************************************************************
  2. // Canvas - Complex Canvas Example
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // All Rights Reserved.
  6. //************************************************************
  7. #include <icolor.hpp>
  8. #include <iscroll.hpp>
  9. #include <istring.hpp>
  10.  
  11. #include "xcanvas.hpp"
  12. #include "xcanvas.h"
  13.  
  14.  
  15. //==================== ComplexCanvasWindow =====================
  16.  
  17. ComplexCanvasWindow :: ComplexCanvasWindow ( )
  18.   : frame( "Multiple Canvas Window" ),
  19.     clientCanvas( 1, &frame, &frame ),
  20.     headingText( 2, &clientCanvas, &clientCanvas ),
  21.     topSeparator( 3, &clientCanvas, &clientCanvas ),
  22.     level1( 4, &clientCanvas, &clientCanvas ),
  23.     horizSplit( 5, &level1, &level1 ),
  24.     vertSplit( 6, &horizSplit, &horizSplit ),
  25.     sizedBmp1( 7, &vertSplit, &vertSplit, ID_FLAMINGO_BMP ),
  26.     sizedBmp2( 8, &vertSplit, &vertSplit, ID_BUTTERFL_BMP ),
  27.     bmpScroller( 9, &horizSplit, &horizSplit,
  28.                  IRectangle(),
  29.                  IViewPort::classDefaultStyle
  30.                    & ~IViewPort::asNeededHorizontalScrollBar
  31.                    & ~IViewPort::asNeededVerticalScrollBar
  32.                    | IViewPort::alwaysHorizontalScrollBar
  33.                    | IViewPort::alwaysVerticalScrollBar
  34.                    | IViewPort::noViewWindowFill ),
  35.     actualSizeBmp( 10, &bmpScroller, &bmpScroller, ID_OS2_BMP ),
  36.     centerSeparator( 11, &level1, &level1 ),
  37.     dlgScroller( 11, &level1 ),
  38.     level2( 12, &dlgScroller, &dlgScroller ),
  39.     prompt( 13, &level2, &level2 ),
  40.     entry( 14, &level2, &level2 ),
  41.     choice1( 15, &level2, &level2 ),
  42.     choice2( 16, &level2, &level2 ),
  43.     listHeading( 17, &level2, &level2 ),
  44.     list( 18, &level2, &level2 ),
  45.     rightSeparator( 19, &level2, &level2 ),
  46.     colorButtons( 20, &level2 ),
  47.     pushButtons( 21, &level2 )
  48. {
  49.   headingText
  50.    .setText( "This window combines several canvases." );
  51.   topSeparator
  52.    .setColor( IStaticText::fill, IColor::black )
  53.    .setMinimumSize( ISize( 1, 1 ));
  54.   centerSeparator
  55.    .setColor( IStaticText::fill, IColor::black )
  56.    .setMinimumSize( ISize( 1, 1 ));
  57.  
  58.   // Set up split canvases.
  59.   horizSplit
  60.    .setOrientation( ISplitCanvas::horizontalSplit )
  61.    .setSplitWindowPercentage( &vertSplit, 33 )
  62.    .setSplitWindowPercentage( &bmpScroller, 67 );
  63.   horizSplit.setMinimumSize( ISize() );
  64.  
  65.   // Set up the dialog portion of the window.
  66.   dlgScroller.setMinimumSize( ISize() );
  67.   prompt.setText( "Enter some data below." );
  68.   entry
  69.    .setLimit( 15 )
  70.    .enableTabStop()
  71.    .enableGroup();
  72.   choice1
  73.    .setText( "~First" )
  74.    .enableTabStop()
  75.    .enableGroup();
  76.   choice2
  77.    .setText( "~Second" );
  78.   listHeading
  79.    .setText( "Below is a list box." );
  80.   list
  81.    .enableTabStop()
  82.    .enableGroup()
  83.    .setMinimumSize( ISize( 50, 50 ));
  84.   rightSeparator
  85.    .setColor( IStaticText::fill, IColor::black )
  86.    .setMinimumSize( ISize( 1, 1 ));
  87.  
  88.   ISize defaultCellSize = IMultiCellCanvas::defaultCell();
  89.   clientCanvas
  90.    .addToCell( &headingText,     1, 2 )
  91.    .addToCell( &topSeparator,    1, 3 )
  92.    .addToCell( &level1,          1, 4 );
  93.   clientCanvas
  94.    .setColumnWidth( 1, 1, true )
  95.    .setRowHeight( 4, 1, true );
  96.  
  97.   level1
  98.    .addToCell( &horizSplit,      1, 1, 2 )
  99.    .addToCell( ¢erSeparator, 3, 1 )
  100.    .addToCell( &dlgScroller,     4, 1, 2 );
  101.   level1
  102.    .setColumnWidth( 2, 1, true )  // Use 1:2 ratio.
  103.    .setColumnWidth( 5, 2, true )
  104.    .setRowHeight( 1, 1, true );
  105.  
  106.   level2
  107.    .addToCell( &prompt,          2, 2,  5 )
  108.    .addToCell( &entry,           2, 4,  5 )
  109.    .addToCell( &choice1,         3, 6 )
  110.    .addToCell( &choice2,         5, 6 )
  111.    .addToCell( &listHeading,     2, 8,  5 )
  112.    .addToCell( &list,            2, 10, 5 )
  113.    .addToCell( &rightSeparator,  8, 1,  1, 11 )
  114.    .addToCell( &colorButtons,    9, 1,  1, 11 );
  115.   level2
  116.    .setColumnWidth( 4, 1, true )
  117.    .setColumnWidth( 6, 1, true )
  118.    .setRowHeight( 10, 1, true )
  119.    .setRowHeight( 11, defaultCellSize.height() );
  120.  
  121.   pushButtons.setMargin( defaultCellSize / 2 );
  122.   frame
  123.    .setClient( &clientCanvas )
  124.    .addExtension( &pushButtons, IFrameWindow::belowClient,
  125.                   (unsigned long)
  126.                     pushButtons.minimumSize().height() )
  127.    .setFocus()
  128.    .show();
  129. }
  130.  
  131. //======================= ColorButtons ========================
  132.  
  133. ColorButtons :: ColorButtons ( unsigned long id,
  134.                                IWindow* parentAndOwner )
  135.   : ISetCanvas( id, parentAndOwner, parentAndOwner ),
  136.     red( 1, this, this, ID_SCREEN_ICON ),
  137.     green( 2, this, this, ID_SCREEN_ICON ),
  138.     blue( 3, this, this, ID_SCREEN_ICON ),
  139.     cyan( 4, this, this, ID_SCREEN_ICON ),
  140.     pink( 5, this, this, ID_SCREEN_ICON )
  141. {
  142.   (*this)
  143.    .setPackType( ISetCanvas::expanded )
  144.    .setDeckOrientation( ISetCanvas::vertical );
  145.  
  146.   ISize colorSize( 40, 40 );
  147.   red
  148.    .setColor( IButton::background, IColor::red )
  149.    .enableTabStop()
  150.    .enableGroup()
  151.    .setMinimumSize( colorSize );
  152.   green
  153.    .setColor( IButton::background, IColor::green )
  154.    .setMinimumSize( colorSize );
  155.   blue
  156.    .setColor( IButton::background, IColor::blue )
  157.    .setMinimumSize( colorSize );
  158.   cyan
  159.    .setColor( IButton::background, IColor::cyan )
  160.    .setMinimumSize( colorSize );
  161.   pink
  162.    .setColor( IButton::background, IColor::pink )
  163.    .setMinimumSize( colorSize );
  164. }
  165.  
  166. //============= ViewPortWithGrowableMinSizeChild ===============
  167.  
  168. ViewPortWithGrowableMinSizeChild::
  169.   ViewPortWithGrowableMinSizeChild ( unsigned long windowId,
  170.                                      IWindow*      parentAndOwner )
  171.   : IViewPort( windowId, parentAndOwner, parentAndOwner,
  172.                IRectangle(),
  173.                IViewPort::classDefaultStyle 
  174.                 | IViewPort::noViewWindowFill )
  175. { }
  176.  
  177. ViewPortWithGrowableMinSizeChild
  178.  &ViewPortWithGrowableMinSizeChild::setLayoutDistorted 
  179.                                  ( unsigned long flagsOn,
  180.                                    unsigned long flagsOff )
  181. {
  182.   if ( flagsOn & IWindow::childMinimumSizeChanged )
  183.   {
  184.      unsigned long newFlagsOn = 
  185.        flagsOn & (unsigned long)(~IWindow::childMinimumSizeChanged);
  186.      newFlagsOn |= IWindow::layoutChanged;
  187.      newFlagsOn |= IWindow::immediateUpdate;
  188.      ICanvas::setLayoutDistorted( newFlagsOn, flagsOff );
  189.   }
  190.   else
  191.   {
  192.      IViewPort::setLayoutDistorted( flagsOn, flagsOff );
  193.   }
  194.   return *this;
  195. }
  196.  
  197. ViewPortWithGrowableMinSizeChild 
  198.  &ViewPortWithGrowableMinSizeChild::layout ( )
  199. {
  200.   if ( this->isLayoutDistorted( IWindow::layoutChanged ))
  201.   {
  202.      IWindow* child = IWindow::windowWithHandle( this->viewWindow() );
  203.      if ( child )
  204.      {
  205.         ISize viewPortSize = this->size();
  206.         ISize minChildSize = child->minimumSize();
  207.         ISize childSize = child->size();
  208.    
  209.         ISize newChildSize = viewPortSize;  // Grow to view port size.
  210.         if ( viewPortSize.width() < minChildSize.width() )
  211.         {     // Don't shrink child smaller than its minimum size.
  212.            newChildSize.setWidth( minChildSize.width() );
  213.         }                  // (Let the view port scroll it.)
  214.         else if ( viewPortSize.height() < minChildSize.height() )
  215.         {         // Allow room for vertical scroll bar if needed.
  216.            newChildSize.setWidth( viewPortSize.width() -
  217.                       this->verticalScrollBar()->size().width() );
  218.            if ( newChildSize.width() < minChildSize.width() )
  219.            {  // Don't shrink child smaller than its minimum size.
  220.               newChildSize.setWidth( minChildSize.width() );
  221.            }               // (Let the view port scroll it.)
  222.         }
  223.    
  224.         if ( viewPortSize.height() < minChildSize.height() )
  225.         {     // Don't shrink child smaller than its minimum size.
  226.            newChildSize.setHeight( minChildSize.height() );
  227.         }                  // (Let the view port scroll it.)
  228.         else if ( viewPortSize.width() < minChildSize.width() )
  229.         {      // Allow room for horizontal scroll bar if needed.
  230.            newChildSize.setHeight( viewPortSize.height() -
  231.                    this->horizontalScrollBar()->size().height() );
  232.            if ( newChildSize.height() < minChildSize.height() )
  233.            {  // Don't shrink child smaller than its minimum size.
  234.               newChildSize.setHeight( minChildSize.height() );
  235.            }               // (Let the view port scroll it.)
  236.         }
  237.    
  238.         if ( newChildSize != childSize )
  239.         {           // Need to resize the child window.
  240.            child->sizeTo( newChildSize );
  241.         }
  242.      }
  243.    
  244.      IViewPort::layout();
  245.   }
  246.   return *this;
  247. }
  248.