home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pwrgu2.zip / POWERGU2.EXE / CANVAS / SETPACK / PACKCV.CPP < prev    next >
Text File  |  1995-08-19  |  6KB  |  188 lines

  1. //************************************************************
  2. // Canvas - ISetCanvas Desks Example                          
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // All Rights Reserved.
  6. //************************************************************
  7. #include "packcv.hpp"
  8. #include "packcv.h"
  9. #include <icconst.h>
  10.  
  11. PackCanvas :: PackCanvas ( unsigned long id,
  12.                            IWindow* parentAndOwner,
  13.                            ISetCanvas::PackType pack )
  14.   : ISetCanvas( id, parentAndOwner, parentAndOwner ),
  15.     first(  1, this, this),
  16.     second( 2, this, this),
  17.     third(  3, this, this),
  18.     fourth( 4, this, this),
  19.     fifth(  5, this, this),
  20.     sixth(  6, this, this)
  21. {
  22.   (*this).setPackType( pack )
  23.          .setDeckCount( 2 );
  24.   switch ( pack )
  25.   {
  26.     case ISetCanvas::tight:
  27.        this->setText( "Pack tight" );
  28.        break;
  29.     case ISetCanvas::even:
  30.        this->setText( "Pack even" );
  31.        break;
  32.     case ISetCanvas::expanded:
  33.     default:
  34.        this->setText( "Pack expanded" );
  35.        break;
  36.   }
  37.   first.setMinimumSize ( ISize( 30, 25 ));
  38.   second.setMinimumSize( ISize( 15, 40 ));
  39.   third.setMinimumSize ( ISize( 35, 65 ));
  40.   fourth.setMinimumSize( ISize( 40, 35 ));
  41.   fifth.setMinimumSize ( ISize( 30, 20 ));
  42.   sixth.setMinimumSize ( ISize( 20, 60 ));
  43. }
  44.  
  45. PackAlignTest :: PackAlignTest ( )
  46.   : IFrameWindow( "ISetCanvas pack options" ),
  47.     packClient( IC_FRAME_CLIENT_ID, this, this ),
  48.     tight( 1, &packClient, ISetCanvas::tight ),
  49.     even( 2, &packClient, ISetCanvas::even ),
  50.     expanded( 3, &packClient, ISetCanvas::expanded ),
  51.     cmdHdr( this ),
  52.     buttons( 0, this, this ),
  53.     topLeft( ID_TOP_LEFT, &buttons, &buttons,
  54.              ID_TOP_LEFT ),
  55.     topCenter( ID_TOP_CENTER, &buttons, &buttons,
  56.                ID_TOP_CENTER ),
  57.     topRight( ID_TOP_RIGHT, &buttons, &buttons,
  58.               ID_TOP_RIGHT ),
  59.     centerLeft( ID_CENTER_LEFT, &buttons, &buttons,
  60.                 ID_CENTER_LEFT ),
  61.     centerCenter( ID_CENTER_CENTER, &buttons, &buttons,
  62.                   ID_CENTER_CENTER ),
  63.     centerRight( ID_CENTER_RIGHT, &buttons, &buttons,
  64.                  ID_CENTER_RIGHT ),
  65.     bottomLeft( ID_BOTTOM_LEFT, &buttons, &buttons,
  66.                 ID_BOTTOM_LEFT ),
  67.     bottomCenter( ID_BOTTOM_CENTER, &buttons, &buttons,
  68.                   ID_BOTTOM_CENTER ),
  69.     bottomRight( ID_BOTTOM_RIGHT, &buttons, &buttons,
  70.                  ID_BOTTOM_RIGHT )
  71. {
  72.   setClient( &packClient );
  73.   packClient.setDeckOrientation( ISetCanvas::horizontal );
  74.   cmdHdr.handleEventsFor( this );
  75.   buttons
  76.    .setMargin( ISize( 1, 1 ))
  77.    .setPad( ISize( 1, 1 ));
  78.   ISize buttonSize( 25, 25 );
  79.   topLeft.setMinimumSize( buttonSize );
  80.   topCenter.setMinimumSize( buttonSize );
  81.   topRight.setMinimumSize( buttonSize );
  82.   centerLeft.setMinimumSize( buttonSize );
  83.   centerCenter.setMinimumSize( buttonSize );
  84.   centerRight.setMinimumSize( buttonSize );
  85.   bottomLeft.setMinimumSize( buttonSize );
  86.   bottomCenter.setMinimumSize( buttonSize );
  87.   bottomRight.setMinimumSize( buttonSize );
  88.   sizHdr
  89.    .handleEventsFor( &topLeft )
  90.    .handleEventsFor( &topCenter )
  91.    .handleEventsFor( &topRight )
  92.    .handleEventsFor( ¢erLeft )
  93.    .handleEventsFor( ¢erCenter )
  94.    .handleEventsFor( ¢erRight )
  95.    .handleEventsFor( &bottomLeft )
  96.    .handleEventsFor( &bottomCenter )
  97.    .handleEventsFor( &bottomRight );
  98.  
  99.   // Add the buttons above the client.
  100.   addExtension( &buttons,
  101.                 IFrameWindow::aboveClient,
  102.                 (unsigned long)buttons.minimumSize()
  103.                  .height() );
  104.  
  105.   // Show the window now.
  106.   IPoint frameNextTopLeft = IFrameWindow::nextShellRect().topLeft();
  107.   ISize clientSize = packClient.minimumSize();
  108.   (*this).moveSizeToClient( IRectangle( IPoint( 0, 0 ),
  109.                                         packClient.minimumSize() ));
  110.   IPoint frameTopLeft = this->rect().topLeft();
  111.   (*this)
  112.    .moveTo( this->position() + frameNextTopLeft - frameTopLeft )
  113.    .setFocus()
  114.    .show();
  115.   IPoint newTopLeft = this->rect().topLeft();
  116. }
  117.  
  118. PackAlignTest& PackAlignTest :: alignGrandChildren
  119.                                  ( ISetCanvas::Alignment align )
  120. {
  121.   tight.setAlignment( align );
  122.   even.setAlignment( align );
  123.   expanded.setAlignment( align );
  124.   return *this;
  125. }
  126.  
  127. Boolean PackAlignTest::CmdHandler :: command
  128.                                         ( ICommandEvent& event )
  129. {
  130.   Boolean dontPassOn = false;
  131.   ISetCanvas::Alignment align = ISetCanvas::bottomRight;
  132.   switch ( event.commandId() )
  133.   {
  134.      case ID_TOP_LEFT:
  135.        align = ISetCanvas::topLeft;
  136.        dontPassOn = true;
  137.        break;
  138.      case ID_TOP_CENTER:
  139.        align = ISetCanvas::topCenter;
  140.        dontPassOn = true;
  141.        break;
  142.      case ID_TOP_RIGHT:
  143.        align = ISetCanvas::topRight;
  144.        dontPassOn = true;
  145.        break;
  146.      case ID_CENTER_LEFT:
  147.        align = ISetCanvas::centerLeft;
  148.        dontPassOn = true;
  149.        break;
  150.      case ID_CENTER_CENTER:
  151.        align = ISetCanvas::centerCenter;
  152.        dontPassOn = true;
  153.        break;
  154.      case ID_CENTER_RIGHT:
  155.        align = ISetCanvas::centerRight;
  156.        dontPassOn = true;
  157.        break;
  158.      case ID_BOTTOM_LEFT:
  159.        align = ISetCanvas::bottomLeft;
  160.        dontPassOn = true;
  161.        break;
  162.      case ID_BOTTOM_CENTER:
  163.        align = ISetCanvas::bottomCenter;
  164.        dontPassOn = true;
  165.        break;
  166.      case ID_BOTTOM_RIGHT:
  167.      default:
  168.        dontPassOn = true;
  169.        break;
  170.   }
  171.   if (dontPassOn)
  172.   {
  173.      clWindow->alignGrandChildren( align );
  174.   }
  175.   return dontPassOn;
  176. }
  177.  
  178. Boolean PackAlignTest::GraphicSizer :: windowResize
  179.                                          ( IResizeEvent& event )
  180. {
  181.   IIconControl* graphic =
  182.      &(((IGraphicPushButton*)event.window())->graphicWindow());
  183.   graphic->moveSizeTo( IRectangle( IPoint( 2, 2 ),
  184.                                    ISize( event.newSize()
  185.                                             - ISize( 4, 4 ))));
  186.   return true;
  187. }
  188.