core/vgui/impl/mfc/vgui_mfc_utils.h
Go to the documentation of this file.
00001 // This is core/vgui/impl/mfc/vgui_mfc_utils.h
00002 #ifndef vgui_mfc_utils_h_
00003 #define vgui_mfc_utils_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief   MFC support for menus.
00010 // \author  Marko Bacic, Oxford RRG
00011 // \date    4 August 2000
00012 //
00013 //  Contains class  vgui_mfc_utils
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   04-AUG-2000 Marko Bacic - Initial version.
00018 //   14-AUG-2000 Marko Bacic - Added support for popup menus
00019 //   16-MAR-2001 K.Y.McGaul - Added menu accelerators
00020 //   22-AUG-2001 K.Y.McGaul - Added destructor to fix memory leak: all
00021 //                            menus now deleted.
00022 //   25-JUL-2006  A. Tamrakar Fixed the "Popup Menu timeout" bug.
00023 // \endverbatim
00024 
00025 #include <vgui/vgui_menu.h>
00026 #include "StdAfx.h"
00027 //: Note that the range 0x8000-0x8400 is reserved for dialog box callbacks
00028 #define ID_MENU_ITEMS 0x8400
00029 #define MAX_ITEM_COUNT 0x400 // (dec 1024)
00030 
00031 typedef void (*fp)();
00032 
00033 //: MFC support for menus.
00034 //  Only one instance of the class is allowed
00035 class vgui_mfc_utils
00036 {
00037   //: Number of menu items.
00038   int item_count;
00039 
00040   //: List of commands to be called by menus.
00041   vcl_vector<vgui_command *> callbacks;
00042 
00043   //: List of menu accelerators.
00044   vcl_vector<ACCEL> accels;
00045 
00046   //: Add keyboard shortcut for this menu item to accelerator table (accels).
00047   void add_menu_accelerator(const vgui_menu_item item, const WORD function_id, vcl_string& the_menu_name);
00048 
00049  public:
00050   //: (Create if necessary and) return singleton instance of this class.
00051   static vgui_mfc_utils *instance();
00052 
00053   //: Constructor.
00054   vgui_mfc_utils() : item_count(0), first_popup(true) {}
00055 
00056   //: Destructor.
00057   ~vgui_mfc_utils();
00058 
00059   //: Create a MFC sub-menu from the given vgui_menu.
00060   HMENU add_submenu(const vgui_menu& menu);
00061 
00062   //: Sets the menu of the application window
00063   void set_menu(const vgui_menu& menu);
00064 
00065   //: Create popup menu.
00066   CMenu *set_popup_menu(const vgui_menu & menu);
00067 
00068   //: Delete the callback functions from the last popup menu.
00069   void delete_last_popup_menu_callbacks();
00070 
00071   //: Called within message service routine of vgui_mfc_mainfrm.
00072   virtual void menu_dispatcher(UINT nID);
00073 
00074   //: Menu accelerator table - this defines menu shortcuts
00075   HACCEL AccelTable;
00076 
00077  private:
00078   //: List of menus to be deleted when we are finished:
00079   vcl_vector<CMenu*> menus_to_be_deleted;
00080 
00081   //: first time a popup menu was created
00082   bool first_popup;
00083 
00084   //: last item_count before a popup menu is created
00085   int last_item_count;
00086 
00087 };
00088 
00089 #endif // vgui_mfc_utils_h_