home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / canvas / setdecks / deckcv.cpp next >
Text File  |  1996-10-29  |  7KB  |  291 lines

  1. //*********************************************************
  2. // Canvas - ISetCanvas Deck Operations
  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 <ipoint.hpp>
  10. #include <irect.hpp>
  11. #include <istring.hpp>
  12. #include "deckcv.hpp"
  13. #include "setdecks.h"
  14.  
  15. DeckCanvas::DeckCanvas ( unsigned long id,
  16.                          IWindow* parentAndOwner,
  17.                          IWindow* frameOrClient )
  18.   : ISetCanvas( id, parentAndOwner, parentAndOwner ),
  19.     cmdHandler( this ),
  20.     childrenCreated( 0 )
  21. {
  22.   cmdHandler
  23.    .handleEventsFor( frameOrClient );
  24.   (*this)
  25.    .makeVertical();   // Set orientation and group box text.
  26. }
  27.  
  28. DeckCanvas::~DeckCanvas ( )
  29. {
  30.   children
  31.    .removeAll( &ChildDeleter );
  32. }
  33.  
  34. unsigned long DeckCanvas :: childCount ( ) const
  35. {
  36.   return children.numberOfElements();
  37. }
  38.  
  39. DeckCanvas& DeckCanvas::setChildCount ( unsigned long count )
  40. {
  41.   while ( childCount() < count )
  42.   {                     // Need to add child windows.
  43.      this->addAsLast();
  44.   }
  45.   while ( childCount() > count )
  46.   {                     // Need to remove child windows.
  47.      this->removeLast();
  48.   }
  49.   return *this;
  50. }
  51.  
  52. DeckCanvas& DeckCanvas::addAsFirst ( )
  53. {
  54.   IStaticText* newChild =
  55.       new IStaticText( childrenCreated + 1, this, this );
  56.   (*this)
  57.    .setUpChild( newChild );
  58.   children
  59.    .addAsFirst( newChild );
  60.   childrenCreated++;
  61.   newChild->positionOnSiblings();  // Force to top.
  62.  
  63.   return *this;
  64. }
  65.  
  66. DeckCanvas& DeckCanvas::addAsLast ( )
  67. {
  68.   IStaticText* newChild =
  69.       new IStaticText( childrenCreated + 1, this, this );
  70.   setUpChild( newChild );
  71.   children.addAsLast( newChild );
  72.   childrenCreated++;
  73.  
  74.   return *this;
  75. }
  76.  
  77. DeckCanvas& DeckCanvas::removeFirst ( )
  78. {
  79.   if ( ! children.isEmpty() )
  80.   {           // There is a child window to delete.
  81.      IStaticText* child = children.firstElement();
  82.      delete child;
  83.      children
  84.       .removeFirst();
  85.   }
  86.   return *this;
  87. }
  88.  
  89. DeckCanvas& DeckCanvas::removeLast ( )
  90. {
  91.   if ( ! children.isEmpty() )
  92.   {           // There is a child window to delete.
  93.      IStaticText* child = children.lastElement();
  94.      delete child;
  95.      children
  96.       .removeLast();
  97.   }
  98.   return *this;
  99. }
  100.  
  101. DeckCanvas& DeckCanvas::setUpChild ( IStaticText* child )
  102. {
  103.   IColor
  104.     bgColor( IColor::red );  // Assign color to child.
  105.   switch ( child->id() % 4 )
  106.   {                          // Alternate colors.
  107.      case 1:
  108.        bgColor = IColor::green;
  109.        break;
  110.      case 2:
  111.        bgColor = IColor::cyan;
  112.        break;
  113.      case 3:
  114.        bgColor = IColor::yellow;
  115.        break;
  116.      case 0:                 // Use default color.
  117.      default:
  118.        break;
  119.   } /* endswitch */
  120.  
  121.   (*child)
  122.    .setAlignment( IStaticText::centerCenter )
  123.    .setText( IString( child->id() ) )
  124.    .setFillColor( bgColor )
  125.    .setForegroundColor( IColor::black )
  126.    .setBackgroundColor( IColor::white )
  127.    .setMinimumSize( ISize( 80, 80 ) );
  128.  
  129.   return *this;
  130. }
  131.  
  132. DeckCanvas& DeckCanvas::makeHorizontal ( )
  133. {
  134.   this->setDeckOrientation( ISetCanvas::horizontal );
  135.   this->setText( "Horizontal decks" );
  136.   return *this;
  137. }
  138.  
  139. DeckCanvas& DeckCanvas::makeVertical ( )
  140. {
  141.   this->setDeckOrientation( ISetCanvas::vertical );
  142.   this->setText( "Vertical decks" );
  143.   return *this;
  144. }
  145.  
  146. DeckCanvas::DeckCommandHandler::DeckCommandHandler
  147.                                     ( DeckCanvas* canvas )
  148.   : deckCanvas( canvas )
  149. { }
  150.  
  151. IBase::Boolean DeckCanvas::DeckCommandHandler::command
  152.                                     ( ICommandEvent& event )
  153. {
  154.   Boolean
  155.     dontPassOn = false;
  156.   switch ( event.commandId() )
  157.   {
  158.      case ID_DECK_HORZ:
  159.      {
  160.         deckCanvas->makeHorizontal();
  161.         dontPassOn = true;
  162.         break;
  163.      }
  164.      case ID_DECK_VERT:
  165.      {
  166.         deckCanvas->makeVertical();
  167.         dontPassOn = true;
  168.         break;
  169.      }
  170.      case ID_DECK_COUNT_1:
  171.      case ID_DECK_COUNT_2:
  172.      case ID_DECK_COUNT_3:
  173.      case ID_DECK_COUNT_4:
  174.      case ID_DECK_COUNT_5:
  175.      case ID_DECK_COUNT_6:
  176.      case ID_DECK_COUNT_7:
  177.      case ID_DECK_COUNT_8:
  178.      case ID_DECK_COUNT_9:
  179.      {
  180.         deckCanvas->setDeckCount( event.commandId()
  181.                                     - ID_DECK_COUNT_1 + 1 );
  182.         dontPassOn = true;
  183.         break;
  184.      }
  185.      case ID_MARGIN_11:
  186.      {
  187.         deckCanvas->setMargin( ISize( 1, 1 ));
  188.         dontPassOn = true;
  189.         break;
  190.      }
  191.      case ID_MARGIN_88:
  192.      {
  193.         deckCanvas->setMargin( ISize( 8, 8 ));
  194.         dontPassOn = true;
  195.         break;
  196.      }
  197.      case ID_MARGIN_XX2:
  198.      {
  199.         deckCanvas->setMargin( deckCanvas->margin()
  200.                                  * ISize( 2, 1 ));
  201.         dontPassOn = true;
  202.         break;
  203.      }
  204.      case ID_MARGIN_XD2:
  205.      {
  206.         deckCanvas->setMargin( deckCanvas->margin()
  207.                                  / ISize( 2, 1 ));
  208.         dontPassOn = true;
  209.         break;
  210.      }
  211.      case ID_MARGIN_YX2:
  212.      {
  213.         deckCanvas->setMargin( deckCanvas->margin()
  214.                                  * ISize( 1, 2 ));
  215.         dontPassOn = true;
  216.         break;
  217.      }
  218.      case ID_MARGIN_YD2:
  219.      {
  220.         deckCanvas->setMargin( deckCanvas->margin()
  221.                                  / ISize( 1, 2 ));
  222.         dontPassOn = true;
  223.         break;
  224.      }
  225.      case ID_PAD_11:
  226.      {
  227.         deckCanvas->setPad( ISize( 1, 1 ));
  228.         dontPassOn = true;
  229.         break;
  230.      }
  231.      case ID_PAD_88:
  232.      {
  233.         deckCanvas->setPad( ISize( 8, 8 ));
  234.         dontPassOn = true;
  235.         break;
  236.      }
  237.      case ID_PAD_XX2:
  238.      {
  239.         deckCanvas->setPad( deckCanvas->pad() * ISize( 2, 1 ));
  240.         dontPassOn = true;
  241.         break;
  242.      }
  243.      case ID_PAD_XD2:
  244.      {
  245.         deckCanvas->setPad( deckCanvas->pad() / ISize( 2, 1 ));
  246.         dontPassOn = true;
  247.         break;
  248.      }
  249.      case ID_PAD_YX2:
  250.      {
  251.         deckCanvas->setPad( deckCanvas->pad() * ISize( 1, 2 ));
  252.         dontPassOn = true;
  253.         break;
  254.      }
  255.      case ID_PAD_YD2:
  256.      {
  257.         deckCanvas->setPad( deckCanvas->pad() / ISize( 1, 2 ));
  258.         dontPassOn = true;
  259.         break;
  260.      }
  261.      case ID_ADD_FIRST:
  262.      {
  263.         deckCanvas->addAsFirst();
  264.         dontPassOn = true;
  265.         break;
  266.      }
  267.      case ID_ADD_LAST:
  268.      {
  269.         deckCanvas->addAsLast();
  270.         dontPassOn = true;
  271.         break;
  272.      }
  273.      case ID_DELETE_FIRST:
  274.      {
  275.         deckCanvas->removeFirst();
  276.         dontPassOn = true;
  277.         break;
  278.      }
  279.      case ID_DELETE_LAST:
  280.      {
  281.         deckCanvas->removeLast();
  282.         dontPassOn = true;
  283.         break;
  284.      }
  285.      default:
  286.         break;
  287.   }
  288.  
  289.   return dontPassOn;
  290. }
  291.