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

  1. //************************************************************
  2. // Menus - Loading a Resource Submenu
  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 <icmdhdr.hpp>
  10. #include <iframe.hpp>
  11. #include <imenubar.hpp>
  12. #include <imenuhdr.hpp>
  13. #include <ipopmenu.hpp>
  14. #include <istattxt.hpp>
  15. #include "addsubmn.h"
  16.  
  17. // Menu handler to capture pop-up menu requests.
  18. class MenuHandler : public IMenuHandler
  19. {
  20. protected:
  21. virtual Boolean
  22.   makePopUpMenu(IMenuEvent& menuEvent);
  23. };
  24.  
  25. // Command handler to capture menu commands.
  26. class CommandHandler : public ICommandHandler
  27. {
  28. public:
  29.   CommandHandler ( IStaticText& status)
  30.             : aStatus(status) {}
  31.  
  32. protected:
  33. virtual Boolean
  34.   command              ( ICommandEvent& event );
  35.  
  36. private:
  37. IStaticText
  38.  &aStatus;
  39. CommandHandler& operator=( const CommandHandler&);
  40. };
  41.  
  42. void main()
  43. {
  44. IFrameWindow
  45.   frame ("Loading a Resource Submenu Example");
  46.  
  47. // Add the Menubar from a resource file.
  48. IMenuBar
  49.   menuBar(MAIN_MENU, &frame);
  50. menuBar.setBitmap(MI_BITMAP, MI_BITMAP);
  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.   // Create an empty pop-up menu
  82.   IPopUpMenu* popUp = new IPopUpMenu( event.window(), POPUP_MENU );
  83.  
  84.   // Load the Edit and Example submenus from a resource.
  85.   (*popUp)
  86.     .addText(MI_EDIT, MI_EDIT)
  87.     .addSubmenu(MI_EDIT,    EDIT_MENU)
  88.     .addText(MI_EXAMPLE, MI_EXAMPLE)
  89.     .addSubmenu(MI_EXAMPLE, EXAMPLE_MENU)
  90.     .setBitmap(MI_BITMAP, MI_BITMAP)
  91.     .setAutoDeleteObject();
  92.  
  93.   // Show the pop-up menu.
  94.   (*popUp)
  95.     .show(event.mousePosition());
  96.   return true;
  97. }
  98.  
  99.  
  100. IBase::Boolean CommandHandler::command( ICommandEvent& event )
  101. {
  102.   switch(event.commandId())
  103.   {
  104.     case MI_FILE          :
  105.     case MI_NEW           :
  106.     case MI_OPEN          :
  107.     case MI_SAVE          :
  108.     case MI_SAVEAS        :
  109.     case MI_EDIT          :
  110.     case MI_UNDO          :
  111.     case MI_CUT           :
  112.     case MI_COPY          :
  113.     case MI_PASTE         :
  114.     case MI_EXAMPLE       :
  115.     case MI_BITMAP        :
  116.     case MI_HELP          :
  117.     case MI_GENERAL_HELP  :
  118.     {
  119.        aStatus.setText(event.commandId());
  120.        return true;
  121.     }
  122.  
  123.   }
  124. return false;
  125. }
  126.  
  127.  
  128.