home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / canvas / complex / xcanvas.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  5.4 KB  |  179 lines

  1. //*********************************************************
  2. // Canvas - Complex Canvas Example
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc.
  6. // All Rights Reserved.
  7. //*********************************************************
  8. #include <icolor.hpp>
  9. #include <iscroll.hpp>
  10. #include <istring.hpp>
  11.  
  12. #include "xcanvas.hpp"
  13. #include "xcanvas.h"
  14.  
  15.  
  16. //==================== ComplexCanvasWindow =====================
  17.  
  18. ComplexCanvasWindow :: ComplexCanvasWindow ( )
  19.   : frame( "Multiple Canvas Window" ),
  20.     clientCanvas( 1, &frame, &frame ),
  21.     headingText( 2, &clientCanvas, &clientCanvas ),
  22.     topSeparator( 3, &clientCanvas, &clientCanvas ),
  23.     level1( 4, &clientCanvas, &clientCanvas ),
  24.     horizSplit( 5, &level1, &level1 ),
  25.     vertSplit( 6, &horizSplit, &horizSplit ),
  26.     sizedBmp1( 7, &vertSplit, &vertSplit, ID_FOUNTAIN_BMP ),
  27.     sizedBmp2( 8, &vertSplit, &vertSplit, ID_OLDBOOK_BMP ),
  28.     bmpScroller( 9, &horizSplit, &horizSplit,
  29.                  IRectangle(),
  30.                  IViewPort::classDefaultStyle
  31.                    & ~IViewPort::asNeededHorizontalScrollBar
  32.                    & ~IViewPort::asNeededVerticalScrollBar
  33.                    | IViewPort::alwaysHorizontalScrollBar
  34.                    | IViewPort::alwaysVerticalScrollBar
  35.                    | IViewPort::noViewWindowFill ),
  36.     actualSizeBmp( 10, &bmpScroller, &bmpScroller, ID_KIDS_BMP ),
  37.     centerSeparator( 11, &level1, &level1 ),
  38.     dlgScroller( 11, &level1, &level1, IRectangle(),
  39.                  IViewPort::classDefaultStyle
  40.                    | IViewPort::expandableViewWindow ),
  41.     level2( 12, &dlgScroller, &dlgScroller ),
  42.     prompt( 13, &level2, &level2 ),
  43.     entry( 14, &level2, &level2 ),
  44.     choice1( 15, &level2, &level2 ),
  45.     choice2( 16, &level2, &level2 ),
  46.     listHeading( 17, &level2, &level2 ),
  47.     list( 18, &level2, &level2 ),
  48.     rightSeparator( 19, &level2, &level2 ),
  49.     colorButtons( 20, &level2 ),
  50.     pushButtons( 21, &level2 )
  51. {
  52.   headingText
  53.    .setText( "This window combines several canvases." );
  54.   topSeparator
  55.    .setFillColor( IColor::black )
  56.    .setMinimumSize( ISize( 1, 1 ));
  57.   centerSeparator
  58.    .setFillColor( IColor::black )
  59.    .setMinimumSize( ISize( 1, 1 ));
  60.  
  61.   // Set up split canvases.
  62.   horizSplit
  63.    .setOrientation( ISplitCanvas::horizontalSplit )
  64.    .setSplitWindowPercentage( &vertSplit, 33 )
  65.    .setSplitWindowPercentage( &bmpScroller, 67 );
  66.   horizSplit
  67.    .setMinimumSize( ISize() );
  68.  
  69.   // Set up the dialog portion of the window.
  70.   dlgScroller
  71.    .setMinimumSize( ISize() );
  72.   prompt.setText( "Enter some data below." );
  73.   entry
  74.    .setLimit( 15 )
  75.    .enableTabStop()
  76.    .enableGroup();
  77.   choice1
  78. #ifdef IC_PM
  79.    .setText( "~First" )
  80. #else
  81.    .setText( "&First" )
  82. #endif
  83.    .enableTabStop()
  84.    .enableGroup();
  85.   choice2
  86. #ifdef IC_PM
  87.    .setText( "~Second" );
  88. #else
  89.    .setText( "&Second" );
  90. #endif
  91.   listHeading
  92.    .setText( "Below is a list box." );
  93.   list
  94.    .enableTabStop()
  95.    .enableGroup()
  96.    .setMinimumSize( ISize( 50, 50 ));
  97.   rightSeparator
  98.    .setFillColor( IColor::black )
  99.    .setMinimumSize( ISize( 1, 1 ));
  100.  
  101.   ISize
  102.     defaultCellSize = IMultiCellCanvas::defaultCell();
  103.   clientCanvas
  104.    .addToCell( &headingText,     1, 2 )
  105.    .addToCell( &topSeparator,    1, 3 )
  106.    .addToCell( &level1,          1, 4 );
  107.   clientCanvas
  108.    .setColumnWidth( 1, 1, true )
  109.    .setRowHeight( 4, 1, true );
  110.  
  111.   level1
  112.    .addToCell( &horizSplit,      1, 1, 2 )
  113.    .addToCell( ¢erSeparator, 3, 1 )
  114.    .addToCell( &dlgScroller,     4, 1, 2 );
  115.   level1
  116.    .setColumnWidth( 2, 1, true )  // Use 1:2 ratio.
  117.    .setColumnWidth( 5, 2, true )
  118.    .setRowHeight( 1, 1, true );
  119.  
  120.   level2
  121.    .addToCell( &prompt,          2, 2,  5 )
  122.    .addToCell( &entry,           2, 4,  5 )
  123.    .addToCell( &choice1,         3, 6 )
  124.    .addToCell( &choice2,         5, 6 )
  125.    .addToCell( &listHeading,     2, 8,  5 )
  126.    .addToCell( &list,            2, 10, 5 )
  127.    .addToCell( &rightSeparator,  8, 1,  1, 11 )
  128.    .addToCell( &colorButtons,    9, 1,  1, 11 );
  129.   level2
  130.    .setColumnWidth( 4, 1, true )
  131.    .setColumnWidth( 6, 1, true )
  132.    .setRowHeight( 10, 1, true )
  133.    .setRowHeight( 11, defaultCellSize.height() );
  134.  
  135.   pushButtons
  136.    .setMargin( defaultCellSize / 2 );
  137.   frame
  138.    .setClient( &clientCanvas )
  139.    .addExtension( &pushButtons, IFrameWindow::belowClient )
  140.    .setFocus()
  141.    .show();
  142. }
  143.  
  144. //======================= ColorButtons ========================
  145.  
  146. ColorButtons::ColorButtons ( unsigned long id,
  147.                              IWindow* parentAndOwner )
  148.   : ISetCanvas( id, parentAndOwner, parentAndOwner ),
  149.     red( 1, this, this, ID_SCREEN_ICON ),
  150.     green( 2, this, this, ID_SCREEN_ICON ),
  151.     blue( 3, this, this, ID_SCREEN_ICON ),
  152.     cyan( 4, this, this, ID_SCREEN_ICON ),
  153.     pink( 5, this, this, ID_SCREEN_ICON )
  154. {
  155.   (*this)
  156.    .setPackType( ISetCanvas::expanded )
  157.    .setDeckOrientation( ISetCanvas::vertical );
  158.  
  159.   ISize
  160.     colorSize( 40, 40 );
  161.   red
  162.    .enableTabStop()
  163.    .enableGroup()
  164.    .setBackgroundColor( IColor::red )
  165.    .setMinimumSize( colorSize );
  166.   green
  167.    .setBackgroundColor( IColor::green )
  168.    .setMinimumSize( colorSize );
  169.   blue
  170.    .setBackgroundColor( IColor::blue )
  171.    .setMinimumSize( colorSize );
  172.   cyan
  173.    .setBackgroundColor( IColor::cyan )
  174.    .setMinimumSize( colorSize );
  175.   pink
  176.    .setBackgroundColor( IColor::pink )
  177.    .setMinimumSize( colorSize );
  178. }
  179.