Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GuiMenu.h

Go to the documentation of this file.
00001 
00002 //
00003 // $Id: GuiMenu.h,v 1.7 2005/07/21 20:26:36 bv Exp $
00004 //
00005 // GuiMenu
00006 //
00007 // Package: MIDAD
00008 //
00009 // Wrap TG menu classes
00010 //
00011 // Contact: bv@bnl.gov
00012 //
00013 // Created on: Thu Nov  8 17:13:07 2001
00014 //
00016 
00017 #ifndef GUIMENU_H
00018 #define GUIMENU_H
00019 
00020 
00021 #include <Midad/Gui/GuiBase.h>
00022 #include <TGMenu.h>
00023 
00024 #include <list>
00025 #include <map>
00026 #include <string>
00027 
00028 class TGLayoutHints;
00029 class GuiMenu;
00030 
00031 class GuiMenuEntry : public SigC::Object 
00032 {
00033     TGMenuEntry* fMenuEntry;
00034     SigC::Signal0<void> fSig;
00035 public:
00036     GuiMenuEntry() : fMenuEntry(0) {}
00037     virtual ~GuiMenuEntry() { }
00038     void Connect(SigC::Slot0<void> s) { fSig.connect(s); }
00039     void Trigger() { fSig.emit(); }
00040     void SetEntry(TGMenuEntry* tgme) { fMenuEntry = tgme; }
00041     TGMenuEntry* GetEntry() { return fMenuEntry; }
00042 };
00043 
00044 class GuiMenu : public TGPopupMenu, public GuiBase
00045 {
00046 
00047 public:
00048 
00049     typedef std::list<SigC::Ptr<GuiMenuEntry> > GuiMenuList;
00050     typedef std::list<SigC::Ptr<GuiMenu> > GuiSubMenuList;
00051 
00052     // GuiMenus don't need parents, so just default constructor
00053     GuiMenu();
00054     
00055     virtual ~GuiMenu() { 
00056         fEntries.erase(fEntries.begin(),fEntries.end()); 
00057     }
00058 
00059     // Override Rt
00060     virtual void Activated(int id);
00061     
00062     // Add a menu item.  Return itr for newly added element
00063     GuiMenuList::iterator Add(const char* label);
00064     GuiMenuList::iterator Add(const char* label, SigC::Slot0<void> slot);
00065     GuiMenuList::iterator Add(const char* label, GuiMenu& menu);
00066     GuiMenuList::iterator Insert(GuiMenuList::iterator gmitr, 
00067                                  const char* label);
00068     GuiMenuList::iterator Insert(GuiMenuList::iterator gmitr, 
00069                                  const char* label,
00070                                  SigC::Slot0<void> slot);
00071     GuiMenuList::iterator Insert(GuiMenuList::iterator gmitr,
00072                                  const char* label, 
00073                                  GuiMenu& menu);
00074     //GuiMenuList::iterator Find(const char* label);
00075     
00076     // Manipulate checkmark on entry.  False clears it
00077     void CheckEntry(GuiMenuList::iterator& mit, bool check_it = true);
00078     bool IsEntryChecked(GuiMenuList::iterator& mit);
00079     GuiMenuList& GetMenuList() { return fEntries; }
00080 
00081     // Clear menu of *all* entries
00082     void ClearAll();
00083 
00084 private:
00085 
00086     void CheckEntry(int) {}     // don't use
00087     bool IsEntryChecked(int) { return false; } // don't use
00088 
00089     GuiMenuList fEntries;
00090     GuiSubMenuList fSubMenus; // for memory management
00091 };                              // end of class GuiMenu
00092 
00093 class GuiMenuBar : public TGMenuBar, public GuiBase
00094 {
00095 public:
00096     typedef std::map<std::string,SigC::Ptr<GuiMenu> > GuiMenuMap;
00097     GuiMenuBar(TGWindow& parent);
00098 
00099     virtual ~GuiMenuBar() { }
00100 
00101     void AddMenu(GuiMenu& menu, const char* label);
00102     GuiMenu* MakeAddMenu(const char* label);
00103 
00104     GuiMenu* GetMenu(const char* label);
00105     void RemoveMenu(const char* label);
00106 
00107 private:
00108 
00109     GuiMenuMap fMenuMap;
00110 
00111 };
00112 
00113 #endif  // GUIMENU_H

Generated on Mon Feb 15 11:06:47 2010 for loon by  doxygen 1.3.9.1