home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / menus / dynaccel / accelupd.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.1 KB  |  124 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 <iaccelky.hpp>
  9. #include <iacceltb.hpp>
  10. #include <icconst.h>
  11. #include <icmd.hpp>
  12. #include <isetbut.hpp>
  13. #include <istring.hpp>
  14. #include "accelupd.hpp"
  15.  
  16. IBase::Boolean
  17.   AccelSelectHandler::selected ( IControlEvent& event )
  18. {
  19.   Boolean
  20.     stopProcessingEvent = false;
  21.   ISettingButton
  22.    *accelButton = (ISettingButton*)( event.controlWindow() );
  23.  
  24.   // Find the accelerator keys associated with the specified
  25.   // window.  Changes to this IAcceleratorTable object can
  26.   // optionally be immediately reflected in the window.
  27.   IAcceleratorTable
  28.     accelTable( &fAccelWindow );
  29.  
  30.   // Add or remove the indicated accelerator key.
  31.   switch ( event.controlId() )
  32.   {
  33.     case ID_RED:
  34.     {
  35.       // Add or remove accelerator keys for:
  36.       //   Ctrl+r = red
  37.       //   Ctrl+R = red
  38.       IAcceleratorKey
  39.         key1( "r", IKey::ctrl,
  40.               ICommand::applicationCommand, CMD_RED ),
  41.         key2( "R", IKey::ctrl,
  42.               ICommand::applicationCommand, CMD_RED );
  43.       if ( accelButton->isSelected() )
  44.       {
  45.          accelTable
  46.           .addKey( key1, false );
  47.          accelTable
  48.           .addKey( key2, true );
  49.       }
  50.       else
  51.       {
  52.          accelTable
  53.           .removeKeyLike( key1, false );
  54.          accelTable
  55.           .removeKeyLike( key2, true );
  56.       }
  57.       stopProcessingEvent = true;
  58.       break;
  59.     }
  60.     case ID_GREEN:
  61.     {
  62.       // Add or remove accelerator keys for F5 = green.
  63.       IAcceleratorKey
  64.         key( IKey::kF5, IKey::noModifier,
  65.              ICommand::applicationCommand, CMD_GREEN );
  66.       if ( accelButton->isSelected() )
  67.       {
  68.          accelTable
  69.           .addKey( key );
  70.       }
  71.       else
  72.       {
  73.          accelTable
  74.           .removeKeyLike( key );
  75.       }
  76.       stopProcessingEvent = true;
  77.       break;
  78.     }
  79.     case ID_CYAN:
  80.     {
  81.       // Add or remove accelerator keys for Ctrl+\ = cyan.
  82.       IAcceleratorKey
  83.         key( "\\", IKey::ctrl,
  84.              ICommand::applicationCommand, CMD_CYAN );
  85.       if ( accelButton->isSelected() )
  86.       {
  87.          accelTable
  88.           .addKey( key );
  89.       }
  90.       else
  91.       {
  92.          accelTable
  93.           .removeKeyLike( key );
  94.       }
  95.       stopProcessingEvent = true;
  96.       break;
  97.     }
  98.     case ID_PINK:
  99.     {
  100.       // Add or remove accelerator keys for
  101.       // Ctrl+Shift+Alt+Home = cyan.
  102.       IAcceleratorKey
  103.         key( IKey::kHome,
  104.              IKey::ctrl | IKey::shift | IKey::alt,
  105.              ICommand::applicationCommand, CMD_PINK );
  106.       if ( accelButton->isSelected() )
  107.       {
  108.          accelTable
  109.           .addKey( key );
  110.       }
  111.       else
  112.       {
  113.          accelTable
  114.           .removeKeyLike( key );
  115.       }
  116.       stopProcessingEvent = true;
  117.       break;
  118.     }
  119.     default:
  120.       break;
  121.   }
  122.   return stopProcessingEvent;
  123. }
  124.