home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / menus / dynaccel / dynaccel.cpp < prev    next >
Text File  |  1996-10-29  |  4KB  |  149 lines

  1. //*********************************************************
  2. // Menus - Dynamic Accelerator Keys
  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 <icconst.h>
  10. #include <icheckbx.hpp>
  11. #include <icmdhdr.hpp>
  12. #include <icolor.hpp>
  13. #include <iframe.hpp>
  14. #include <isetcv.hpp>
  15. #include <istattxt.hpp>
  16. #include "accelupd.hpp"
  17.  
  18. #define ID_RED     10
  19. #define ID_GREEN   11
  20. #define ID_CYAN    12
  21. #define ID_PINK    13
  22.  
  23. #define CMD_RED    100
  24. #define CMD_GREEN  101
  25. #define CMD_CYAN   102
  26. #define CMD_PINK   103
  27.  
  28. // This command handler changes the color of a window.
  29. class ColorCmdHandler : public ICommandHandler {
  30. public:
  31.   ColorCmdHandler ( IWindow& colorWindow )
  32.     : fColorWindow( colorWindow )
  33.   { }
  34. protected:
  35. virtual Boolean
  36.   command ( ICommandEvent& event )
  37.   {
  38.     Boolean
  39.       stopProcessingEvent = false;
  40.     switch ( event.commandId() )
  41.     {
  42.       case CMD_RED:
  43.         fColorWindow
  44.          .setForegroundColor( IColor::white )
  45.          .setBackgroundColor( IColor::red );
  46.         stopProcessingEvent = true;
  47.         break;
  48.       case CMD_GREEN:
  49.         fColorWindow
  50.          .setForegroundColor( IColor::white )
  51.          .setBackgroundColor( IColor::green );
  52.         stopProcessingEvent = true;
  53.         break;
  54.       case CMD_CYAN:
  55.         fColorWindow
  56.          .setForegroundColor( IColor::blue )
  57.          .setBackgroundColor( IColor::cyan );
  58.         stopProcessingEvent = true;
  59.         break;
  60.       case CMD_PINK:
  61.         fColorWindow
  62.          .setForegroundColor( IColor::blue )
  63.          .setBackgroundColor( IColor::pink );
  64.         stopProcessingEvent = true;
  65.         break;
  66.       default:
  67.         break;
  68.     }
  69.     return stopProcessingEvent;
  70.   }
  71. private:
  72.   ColorCmdHandler ( const ColorCmdHandler& );
  73. ColorCmdHandler
  74.  &operator=       ( const ColorCmdHandler& );
  75. IWindow
  76.  &fColorWindow;
  77. }; // ColorCmdHandler
  78.  
  79. void main ( )
  80. {
  81.   // Create a frame window with a static text control that
  82.   // changes color based on the press of accelerator keys.
  83.   IFrameWindow
  84.     frame( "Dynamic Accelerator Keys" );
  85.   IStaticText
  86.     testArea( IC_FRAME_CLIENT_ID, &frame, &frame );
  87.   testArea
  88.    .setAlignment( IStaticText::centerCenter )
  89.    .setText( "Change this color by pressing an "
  90.              "accelerator key" );
  91.  
  92.   ISetCanvas
  93.     instructions( 1, &frame, &frame );
  94.   instructions
  95.    .setDeckOrientation( ISetCanvas::vertical );
  96.   IStaticText
  97.     instructions1( 2, &instructions, &instructions ),
  98.     instructions2( 3, &instructions, &instructions );
  99.   instructions1
  100.    .setText( "Enable and disable accelerator keys by "
  101.              "selecting check boxes." );
  102.   instructions2
  103.    .setText( "Press accelerator keys to change the color "
  104.              "of the test area." );
  105.  
  106.   ISetCanvas
  107.     accelChoices( 4, &frame, &frame );
  108.   accelChoices
  109.    .setDeckOrientation( ISetCanvas::vertical );
  110.   ICheckBox
  111.     redChoice( ID_RED, &accelChoices, &accelChoices ),
  112.     greenChoice( ID_GREEN, &accelChoices, &accelChoices ),
  113.     cyanChoice( ID_CYAN, &accelChoices, &accelChoices ),
  114.     pinkChoice( ID_PINK, &accelChoices, &accelChoices );
  115.   redChoice
  116.    .setText( "Ctrl+R = Red" )
  117.    .enableTabStop()
  118.    .enableGroup();
  119.   greenChoice
  120.    .setText( "F5 = Green" );
  121.   cyanChoice
  122.    .setText( "Ctrl+\\ = Cyan" );
  123.   pinkChoice
  124.    .setText( "Ctrl+Shift+Alt+Home = Pink" );
  125.  
  126.   // Create a command handler to process the accelerator keys.
  127.   ColorCmdHandler
  128.     cmdHandler( testArea );
  129.   cmdHandler
  130.    .handleEventsFor( &frame );
  131.  
  132.   // Create a selection handler to add or remove accelerator
  133.   // keys.
  134.   AccelSelectHandler
  135.     selHandler( frame );
  136.   selHandler
  137.    .handleEventsFor( &accelChoices );
  138.  
  139.   // Show the window.
  140.   frame
  141.    .setClient( &testArea )
  142.    .addExtension( &instructions, IFrameWindow::aboveClient )
  143.    .addExtension( &accelChoices, IFrameWindow::leftOfClient )
  144.    .setFocus()
  145.    .show();
  146.  
  147.   IApplication::current().run();
  148. }
  149.