00001 /*-------------------------------------------------------------------- 00002 * vmenu.h 00003 * 00004 * This class allows menus to be created easily. 00005 * Menus and submenus are represented by a menu path, in a form similar 00006 * to a file path name, separated by '/'s, starting from the root menu. 00007 * e.g. "a/b/c" represents the menu with menubutton labeled "a", and 00008 * cascade menus "b", and then "c". 00009 * 00010 * Cascade menus are automatically created. So for instance, a call to 00011 * add_command(b, "a/b/c", "test") will create the menubutton "a", and 00012 * submenus "a/b" and "a/b/c". 00013 * 00014 */ 00015 00016 #ifndef VMENU_H 00017 #define VMENU_H 00018 00019 #include "tcltk_calling_convention.h" 00020 //#include <sty.h> 00021 #include "vwidget.h" 00022 #include "vtcl.h" 00023 #include "binding.h" 00024 00025 #define ROOT_MENU "" // The root of the menu. 00026 00027 /*---------------------------------------------------------------------- 00028 * menu class 00029 */ 00030 class vmenu : public vwidget { 00031 00032 public: 00033 vmenu(vwidget *par); 00034 ~vmenu(void); 00035 void destroy(void); 00036 virtual int kind(void) { return WIDGET_MENU; } 00037 00038 /* add a menu */ 00039 void add_menu(binding *b, char *menu); 00040 00041 /* add a menu command/radio button/checkbox/separator */ 00042 void add_command(binding *b, const char *menu, const char *text, 00043 const char *accelerator = ""); 00044 void add_radio(binding *b, char *menu, char *text, bool on = false); 00045 void add_check(binding *b, char *menu, char *text, bool on = false); 00046 void add_separator(char *menu); 00047 00048 /* clear the menu */ 00049 void clear(char *menu); /* remove all items in the menu */ 00050 void remove(char *menu); /* remove the menu */ 00051 00052 /* invoke a menu item */ 00053 void invoke(char *menu, char *item_name); 00054 00055 /* interface with tcl/tk */ 00056 static int TCLTK_CALLING_CONVENTION vmenu_cmd(ClientData clientData, Tcl_Interp *interp, int argc, 00057 char *argv[]); 00058 }; 00059 00060 00061 /*---------------------------------------------------------------------- 00062 * virtual menu class 00063 */ 00064 class virtual_menu { 00065 00066 protected: 00067 vmenu *par_menu; 00068 char *root_path; 00069 00070 char *get_menu_path(const char *menu_str); 00071 00072 public: 00073 virtual_menu(void); 00074 void attach(vmenu *parent_menu, char *path); 00075 00076 void add_command(binding *b, const char *menupath, const char *text, 00077 const char *accelerator = ""); 00078 void add_radio(binding *b, char *menupath, char *text); 00079 void add_check(binding *b, char *menupath, char *text, bool on); 00080 void add_separator(char *menupath); 00081 00082 void clear(char *menu); 00083 }; 00084 00085 #endif