home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / advframe / drawextn / myframe.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.1 KB  |  115 lines

  1. //************************************************************
  2. // Advanced Frame - Frame Extension Drawing 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 <istring.hpp>
  9.  
  10. #include "myframe.hpp"
  11. #include "myextns.hpp"
  12.  
  13. static IString
  14.   colorText("white blue red pink green cyan "
  15.             "yellow black darkGray darkBlue darkRed "
  16.             "darkPink darkGreen darkCyan brown paleGray" );
  17.  
  18. ColorList::ColorList ( IWindow *owner )
  19.     : IListBox( 0, owner, owner )
  20.   {
  21.   for ( int i = 1; i <= colorText.numWords(); i++ )
  22.      addAsLast( colorText.word( i ) );
  23.   }
  24.  
  25. IColor ColorList:: selectedColor ( ) const
  26.   {
  27.   IString
  28.     selected( itemText( selection() ) );
  29.   return IColor(
  30.      (IColor::Color) (colorText.wordIndexOfPhrase(selected) - 1));
  31.   }
  32.  
  33. MyFrame::MyFrame ( )
  34.     : IFrameWindow( "Extended Extension Test" ),
  35.       colorList( this ),
  36.       extSize( 1, this, this ),
  37.       instructions( IC_FRAME_CLIENT_ID, this, this ),
  38.       drawButton( 2, this, this ),
  39.       handler( *this )
  40.   {
  41.   instructions.setAlignment( IStaticText::topLeftWrapped );
  42.   instructions.setText( "Select a color and/or\n"
  43.                         "enter a new separator width,\n"
  44.                         "and press Redraw to apply changes" );
  45.   setClient( &instructions );
  46.   drawButton.setText( "Redraw" );
  47.   extSize.setText( "5" );
  48.   colorList.select( 0 );
  49.   addMyExtension( new MyExtension( &drawButton,
  50.                                     belowClient ) );
  51.   addMyExtension( new MyExtension( &colorList,
  52.                                    aboveClient, 0.5 ) );
  53.   addMyExtension( new MyExtension( &extSize,
  54.                                    aboveClient ) );
  55.   update();
  56.   }
  57.  
  58. IFrameWindow& MyFrame::update ( )
  59.   {
  60.   IFrameExtensions
  61.    *exts = extensions();
  62.   unsigned long
  63.     newWidth = extSize.text().asUnsigned();
  64.   IColor
  65.     newColor = colorList.selectedColor();
  66.   for ( int i = 1; exts && i <= exts->numberOfElements(); i++ )
  67.     {
  68.     MyExtension
  69.      *p = (MyExtension*)( exts->elementAtPosition(i) );
  70.     p -> setSeparatorWidth( newWidth );
  71.     p -> setSeparatorColor( newColor );
  72.     }
  73.  
  74.   return IFrameWindow::update();
  75.   }
  76.  
  77. MyFrame &MyFrame :: forceUpdate ( )
  78.   {
  79.   // Resize extension to force update.
  80.   if ( this->isAnExtension( &drawButton ) )
  81.     useExtensionMinimumSize( &drawButton );
  82.   this -> update();
  83.   return *this;
  84.   }
  85.  
  86. MyFrame&  MyFrame::addMyExtension( MyExtension *pExt )
  87.   {
  88.   // Get frame extensions.
  89.   IFrameExtensions
  90.    *exts = this->extensions();
  91.  
  92.   // If no previous extensions, allocate collection.
  93.   if ( !exts )
  94.     this->setExtensions( exts = new IFrameExtensions );
  95.  
  96.   // Add argument extension to collection.
  97.   exts -> addAsLast( pExt );
  98.  
  99.   // Update the frame.
  100.   forceUpdate();
  101.   return *this;
  102.   }
  103.  
  104. MyHandler :: MyHandler ( MyFrame &frame )
  105.   : frame( frame )
  106.   {
  107.   handleEventsFor( &frame );
  108.   }
  109.  
  110. Boolean MyHandler :: command ( ICommandEvent &event )
  111.   {
  112.   frame.forceUpdate().refresh();
  113.   return true;
  114.   }
  115.