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

  1. //************************************************************
  2. // Menus - Static Text Pop-up 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 <iframe.hpp>
  9. #include <istattxt.hpp>
  10. #include <iapp.hpp>
  11. #include <ipopmenu.hpp>
  12. #include <imenuhdr.hpp>
  13. #include <icmdhdr.hpp>
  14. #include "txtpopup.h"
  15.  
  16. // Menu handler to capture pop-up menu requests.
  17. class MenuHandler : public IMenuHandler
  18. {
  19. protected:
  20. virtual Boolean
  21.   makePopUpMenu(IMenuEvent& menuEvent);
  22. };
  23.  
  24. // Command handler to capture menu commands.
  25. class CommandHandler : public ICommandHandler
  26. {
  27. public:
  28.   CommandHandler ( IStaticText& status)
  29.             : aStatus(status) {}
  30.  
  31. protected:
  32. virtual Boolean
  33.   command              ( ICommandEvent& event );
  34.  
  35. private:
  36. IStaticText
  37.  &aStatus;
  38. CommandHandler ( const CommandHandler&);
  39. CommandHandler& operator=( const CommandHandler&);
  40. };
  41.  
  42. void main()
  43. {
  44. // Create a frame window with a menubar and an
  45. // accelerator table from a resource file.
  46. IFrameWindow
  47.   frame ("Pop-Up Menu Example", MAIN_MENU,
  48.          IFrameWindow::defaultStyle()
  49.                 | IFrameWindow::menuBar
  50.                 | IFrameWindow::accelerator);
  51.  
  52. // Create a Status Area in the Client
  53. // and a command handler to write in it.
  54. IStaticText
  55.   statusArea(ID_STATUS, &frame, &frame);
  56. CommandHandler
  57.   commandHandler(statusArea);
  58.  
  59. // Add the command handler to the frame to receive the
  60. // menu commands and to the status area to receive any
  61. // pop-up menu commands sent.
  62. commandHandler
  63.   .handleEventsFor(&frame)
  64.   .handleEventsFor(&statusArea);
  65.  
  66. // Add a PopUp menu handler to the client status area..
  67. MenuHandler
  68.   textPopUpHandler;
  69. textPopUpHandler.handleEventsFor(&statusArea);
  70.  
  71. // Set the focus and show the application.
  72. frame
  73.   .setClient(&statusArea)
  74.   .setFocus()
  75.   .show();
  76. IApplication::current().run();
  77. }
  78.  
  79. IBase::Boolean MenuHandler::makePopUpMenu(IMenuEvent& event)
  80. {
  81.   IPopUpMenu* popUp = new IPopUpMenu( POPUP_MENU,
  82.                                       event.window() );
  83.   (*popUp)
  84.     .show(event.mousePosition())
  85.     .setAutoDeleteObject();
  86.   return true;
  87. }
  88.  
  89.  
  90. IBase::Boolean CommandHandler::command( ICommandEvent& event )
  91. {
  92.   switch(event.commandId())
  93.   {
  94.     case MI_FILE          :
  95.     case MI_NEW           :
  96.     case MI_OPEN          :
  97.     case MI_SAVE          :
  98.     case MI_SAVEAS        :
  99.     case MI_EDIT          :
  100.     case MI_UNDO          :
  101.     case MI_CUT           :
  102.     case MI_COPY          :
  103.     case MI_PASTE         :
  104.     case MI_EXAMPLE       :
  105.     case MI_BITMAP        :
  106.     case MI_HELP          :
  107.     case MI_GENERAL_HELP  :
  108.     case MI_CASCADE1      :
  109.     case MI_CASCADE2      :
  110.     case MI_CASCADE3      :
  111.     {
  112.        aStatus.setText(event.commandId());
  113.        return true;
  114.     }
  115.   }
  116. return false;
  117. }
  118.  
  119.