home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / menus / accel / accel.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  2.4 KB  |  96 lines

  1. //************************************************************
  2. // Menus  - Using an Accelerator Table Resource
  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 <iaccel.hpp>
  9. #include <iapp.hpp>
  10. #include <icmdhdr.hpp>
  11. #include <iframe.hpp>
  12. #include <istattxt.hpp>
  13. #include "accel.h"
  14.  
  15. // Command handler to capture menu commands.
  16. class CommandHandler : public ICommandHandler
  17. {
  18. public:
  19.   CommandHandler ( IStaticText& status)
  20.             : aStatus(status) {}
  21.  
  22. protected:
  23. virtual Boolean
  24.   command              ( ICommandEvent& event );
  25.  
  26. private:
  27. IStaticText
  28.  &aStatus;
  29. CommandHandler ( const CommandHandler&);
  30. CommandHandler& operator= ( const CommandHandler&);
  31. };
  32.  
  33. void main()
  34. {
  35. // Create a frame window with a menubar.
  36. IFrameWindow
  37.   frame ("Accelerator Example", MAIN_MENU,
  38.          IFrameWindow::defaultStyle()
  39.                 | IFrameWindow::menuBar);
  40.  
  41. // Load an Accelerator table from the resource
  42. // file and associate it with our frame window.
  43. IAccelerator accelTable(MAIN_MENU, &frame);
  44.  
  45. // Create a Status Area in the Client
  46. // and a command handler to write in it.
  47. IStaticText
  48.   statusArea(ID_STATUS, &frame, &frame);
  49. CommandHandler
  50.   commandHandler(statusArea);
  51.  
  52. // Add the command handler to the frame to receive the
  53. // menu commands and to the status area to receive any
  54. // accelerator commands sent.
  55. commandHandler
  56.   .handleEventsFor(&frame)
  57.   .handleEventsFor(&statusArea);
  58.  
  59. // Set the focus and show the application.
  60. frame
  61.   .setClient(&statusArea)
  62.   .setFocus()
  63.   .show();
  64. IApplication::current().run();
  65. }
  66.  
  67. IBase::Boolean CommandHandler::command( ICommandEvent& event )
  68. {
  69.   switch(event.commandId())
  70.   {
  71.     case MI_FILE          :
  72.     case MI_NEW           :
  73.     case MI_OPEN          :
  74.     case MI_SAVE          :
  75.     case MI_SAVEAS        :
  76.     case MI_EDIT          :
  77.     case MI_UNDO          :
  78.     case MI_CUT           :
  79.     case MI_COPY          :
  80.     case MI_PASTE         :
  81.     case MI_EXAMPLE       :
  82.     case MI_BITMAP        :
  83.     case MI_HELP          :
  84.     case MI_GENERAL_HELP  :
  85.     case MI_CASCADE1      :
  86.     case MI_CASCADE2      :
  87.     case MI_CASCADE3      :
  88.     {
  89.        aStatus.setText(event.commandId());
  90.        return true;
  91.     }
  92.   }
  93. return false;
  94. }
  95.  
  96.