home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / canvas / mcsimple / mcsimple.cpp < prev   
Encoding:
C/C++ Source or Header  |  1996-10-29  |  2.3 KB  |  82 lines

  1. //*********************************************************
  2. // Canvas - Simple IMultiCellCanvas 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 <iapp.hpp>
  9. #include <icolor.hpp>
  10. #include <iframe.hpp>
  11. #include <imcelcv.hpp>
  12. #include <ipushbut.hpp>
  13. #include <isysmenu.hpp>
  14. #include <icconst.h>
  15.  
  16. void main ( )
  17. {
  18.   IFrameWindow
  19.     frame( "Multicell Canvas Example" );
  20.   IMultiCellCanvas
  21.     client( IC_FRAME_CLIENT_ID, &frame, &frame );
  22.  
  23.   // Create three color squares using ICanvas objects.
  24.   // Do not let the squares get smaller than 20x20 pels.
  25.   ICanvas
  26.     red  ( 1, &client, &client ),
  27.     green( 2, &client, &client ),
  28.     blue ( 3, &client, &client );
  29.   red
  30.    .setBackgroundColor( IColor::red )
  31.    .setMinimumSize( ISize( 20, 20 ) );
  32.   green
  33.    .setBackgroundColor( IColor::green )
  34.    .setMinimumSize( ISize( 20, 20 ) );
  35.   blue
  36.    .setBackgroundColor( IColor::blue )
  37.    .setMinimumSize( ISize( 20, 20 ) );
  38.  
  39.   // Create a push button.
  40.   IPushButton
  41.     ok( ISystemMenu::idClose, &client, &client );
  42.   ok
  43.    .enableDefault()
  44.    .enableSystemCommand()  // For ISystemMenu::idClose.
  45.    .setText( "OK" )
  46.    .enableTabStop()
  47.    .enableGroup();
  48.  
  49.   // Position child windows in the canvas.
  50.   client
  51.    .addToCell( &red,   2, 2, 2, 2 )
  52.    .addToCell( &green, 3, 3, 3, 2 )
  53.    .addToCell( &blue,  5, 2, 2, 2 )
  54.    .addToCell( &ok,    2, 6, 5 );
  55.  
  56.   // Use expandable rows and columns so that the squares always
  57.   // fill the canvas.  Set the overlap amount to be 25% of the
  58.   // child windows' width and height via the ratios we pass to
  59.   // setColumnWidth and setRowHeight.
  60.   ISize
  61.     defaultCellSize = IMultiCellCanvas::defaultCell();
  62.   client
  63.    .setColumnWidth( 2, 3, true )
  64.    .setColumnWidth( 3, 1, true )
  65.    .setColumnWidth( 4, 2, true )
  66.    .setColumnWidth( 5, 1, true )
  67.    .setColumnWidth( 6, 3, true )
  68.    .setColumnWidth( 7, defaultCellSize.width() )
  69.    .setRowHeight( 2, 3, true )
  70.    .setRowHeight( 3, 1, true )
  71.    .setRowHeight( 4, 3, true )
  72.    .setRowHeight( 7, defaultCellSize.height() );
  73.  
  74.   // Size and show the window now.
  75.   frame
  76.    .setClient( &client )
  77.    .setFocus()
  78.    .show();
  79.  
  80.   IApplication::current().run();
  81. }
  82.