core/vgui/impl/win32/vgui_win32_utils.h
Go to the documentation of this file.
00001 // This is core/vgui/impl/win32/vgui_win32_utils.h
00002 
00003 #ifndef vgui_win32_utils_h
00004 #define vgui_win32_utils_h
00005 
00006 #include <windows.h>
00007 #include <vgui/vgui_menu.h>
00008 
00009 // The definitions of MENUEX_TEMPLATE_HEADER and MENUEX_TEMPLATE_ITEM
00010 // are not present in any standard header file. They are copied here
00011 // from MSDN documentation.
00012 // We use MENUEX_TEMPLATE_HEADER and MENUEX_TEMPLATE_ITEM instead of
00013 // MENUITEMTEMPLATEHEADER and MENUITEMTEMPLATE because a separator is
00014 // not defined in the latter.
00015 typedef struct
00016 {
00017   WORD  wVersion; // typedef unsigned short WORD;
00018   WORD  wOffset;
00019   DWORD dwHelpId; // typedef unsigned long DWORD;
00020 } MENUEX_TEMPLATE_HEADER;
00021 
00022 typedef struct
00023 {
00024   DWORD dwType;
00025   DWORD dwState;
00026   DWORD menuId;
00027   WORD  bResInfo;
00028   WCHAR szText;   // variable length;
00029   DWORD dwHelpId; // only included for submenu
00030 } MENUEX_TEMPLATE_ITEM;
00031 
00032 #define MENU_ID_START      0x8400
00033 #define POPUPMENU_ID_START 0x8600
00034 
00035 class vgui_win32_utils
00036 {
00037  public:
00038   // (Create if necessary and) return singleton instance of this class.
00039   static vgui_win32_utils *instance();
00040 
00041   // Convert a vgui_menu to a Win32 menu
00042   HMENU vgui_menu_to_win32(vgui_menu const &vguimenu,
00043                            vcl_vector<vgui_command_sptr> &callbacks, HACCEL *hAccel,
00044                            bool isPopup = false);
00045 
00046   // Convert a vgui_menu to an extended Win32 menu
00047   HMENU vgui_menu_to_win32ex(vgui_menu const &vguimenu,
00048                              vcl_vector<vgui_command_sptr> &callbacks, HACCEL *hAccel,
00049                              bool isPopup = false);
00050 
00051  protected:
00052   vgui_win32_utils() {}
00053   ~vgui_win32_utils() {}
00054 
00055  private:
00056   int addMenuItems(vgui_menu const &vguimenu, int offset, bool is_popup);
00057   int addMenuItemsEx(vgui_menu const &vguimenu, int offset, bool is_popup);
00058   void addAccelerator(vcl_string&, vgui_menu_item const&, int);
00059   vcl_string vgui_key_to_string(vgui_key);
00060   UINT vgui_key_to_virt_key(vgui_key);
00061 
00062   // Show explainary message for GetLastError().
00063   void ShowErrorMessage(DWORD dwErrorNo);
00064 
00065   unsigned char *pMenu; // menu template buffer
00066   int menu_capacity; // menu template length
00067   vcl_vector<vgui_command_sptr> callbacks; // commands called by menu items
00068   int item_count; // count of menu items
00069 
00070   ACCEL *pAccel; // pointer to accelerator table, varying length;
00071   int accel_capacity;
00072   int accel_count; // count of accelerators
00073 };
00074 
00075 #endif // vgui_win32_utils_h