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

GuiMenu.cxx

Go to the documentation of this file.
00001 #include "GuiMenu.h"
00002 #include "TVirtualX.h"
00003 
00004 using namespace std;
00005 
00006 
00007 GuiMenu::GuiMenu() : TGPopupMenu(0) 
00008 {
00009     SetLayoutHints(kLHintsTop|kLHintsLeft); 
00010 }
00011 
00012 void GuiMenu::Activated(int id)
00013 {
00014     gVirtualX->Update(1);       // XSync
00015     // could change pointer here....
00016     this->TGPopupMenu::Activated(id);
00017     GuiMenuEntry* gme = (GuiMenuEntry*)id; // yes, I am evil.
00018     gme->Trigger();
00019 }
00020     
00021 GuiMenu::GuiMenuList::iterator 
00022 GuiMenu::Add(const char* label)
00023 {
00024     if (label)
00025         return this->Insert(fEntries.end(),label);
00026     else {
00027         this->AddSeparator(0);
00028         return fEntries.end();
00029     }        
00030 }
00031 GuiMenu::GuiMenuList::iterator 
00032 GuiMenu::Add(const char* label, SigC::Slot0<void> slot)
00033 {
00034     return this->Insert(fEntries.end(),label,slot);
00035 }
00036 GuiMenu::GuiMenuList::iterator
00037 GuiMenu::Add(const char* label, GuiMenu& menu)
00038 {
00039     return this->Insert(fEntries.end(), label, menu);
00040 }
00041 
00042 GuiMenu::GuiMenuList::iterator
00043 GuiMenu::Insert(GuiMenuList::iterator gmitr, const char* label)
00044 {
00045     GuiMenuEntry* gme = manage(new GuiMenuEntry);
00046 
00047     int id = (int)gme;          // evil
00048 
00049     if (gmitr == fEntries.end()) 
00050         this->AddEntry(label,id);
00051     else
00052         this->AddEntry(label,id,0,0,(*gmitr)->GetEntry());
00053     gme->SetEntry(this->GetEntry(id));
00054     return fEntries.insert(gmitr,gme);
00055 }
00056 GuiMenu::GuiMenuList::iterator
00057 GuiMenu::Insert(GuiMenuList::iterator gmitr, const char* label, 
00058                 SigC::Slot0<void> s)
00059 {
00060     GuiMenuEntry* gme = manage(new GuiMenuEntry);
00061     gme->Connect(s);
00062 
00063     int id = (int)gme;          // evil
00064 
00065     if (gmitr == fEntries.end()) 
00066         this->AddEntry(label,id);
00067     else
00068         this->AddEntry(label,id,0,0,(*gmitr)->GetEntry());
00069     gme->SetEntry(this->GetEntry(id));
00070     return fEntries.insert(gmitr,gme);
00071 }
00072 GuiMenu::GuiMenuList::iterator
00073 GuiMenu::Insert(GuiMenuList::iterator gmitr, 
00074                 const char* label, GuiMenu& menu)
00075 {
00076     menu.GuiBase::SetName(label);
00077 
00078     GuiMenuEntry* gme = manage(new GuiMenuEntry);
00079     fSubMenus.push_back(&menu);
00080 
00081     if (gmitr == fEntries.end()) 
00082         this->AddPopup(label,&menu);
00083     else
00084         this->AddPopup(label,&menu,(*gmitr)->GetEntry());
00085     gme->SetEntry(this->GetEntry(label));
00086     return fEntries.insert(gmitr,gme);    
00087 }
00088 
00089 void GuiMenu::CheckEntry(GuiMenuList::iterator& mit, bool check_it)
00090 {
00091     GuiMenuEntry* gme = *mit;
00092 
00093     if (check_it)
00094         this->TGPopupMenu::CheckEntry((int)gme);
00095     else
00096         this->TGPopupMenu::UnCheckEntry((int)gme);
00097 }
00098 bool GuiMenu::IsEntryChecked(GuiMenuList::iterator& mit)
00099 {
00100     GuiMenuEntry* gme = *mit;
00101     return this->TGPopupMenu::IsEntryChecked((int)gme);
00102 }
00103 
00104 void GuiMenu::ClearAll()
00105 {
00106     GuiSubMenuList::iterator smit, send = fSubMenus.end();
00107     for (smit = fSubMenus.begin(); smit != send; ++smit) 
00108         (*smit)->ClearAll();
00109 
00110     GuiMenuList::iterator mit, end = fEntries.end();
00111     for (mit = fEntries.begin(); mit != end; ++mit)
00112         this->DeleteEntry((*mit)->GetEntry());
00113       
00114     fSubMenus.clear();
00115     fEntries.clear();
00116 }
00117 
00118 
00119 // GuiMenuBar:
00120 
00121 GuiMenuBar::GuiMenuBar(TGWindow& parent)
00122     : TGMenuBar(&parent,1,1,kHorizontalFrame)
00123 {
00124     SetLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX);
00125 }
00126 
00127 void GuiMenuBar::AddMenu(GuiMenu& menu, const char* label)
00128 {
00129     if(! this->AddChild(menu)) return;
00130 
00131     menu.GuiBase::SetName(label);
00132 
00133     TGLayoutHints* loh = 
00134         new TGLayoutHints(menu.GetLayoutHints());
00135     this->AddObject(loh);
00136     this->AddPopup(label,&menu,loh);
00137     fMenuMap[label] = &menu;
00138     this->MapSubwindows();
00139     this->Layout();
00140     this->MapWindow();
00141 }
00142 
00143 GuiMenu* GuiMenuBar::MakeAddMenu(const char* label)
00144 {
00145     GuiMenu* menu = manage(new GuiMenu);
00146     this->AddMenu(*menu,label);
00147     return menu;
00148 }
00149 
00150 GuiMenu* GuiMenuBar::GetMenu(const char* label)
00151 {
00152     GuiMenuMap::iterator mit = fMenuMap.find(label);
00153     if (mit == fMenuMap.end()) return 0;
00154     return mit->second;
00155 }
00156 
00157 void GuiMenuBar::RemoveMenu(const char* label)
00158 {
00159     GuiMenuMap::iterator mit = fMenuMap.find(label);
00160     if (mit == fMenuMap.end()) return;
00161     this->TGMenuBar::RemovePopup(label);
00162 
00163     GuiBase* gb = mit->second;  // quell harmless sigc++ compile warnings
00164     fChildren.remove(gb);
00165     fMenuMap.erase(mit);    
00166     this->MapSubwindows();
00167     this->Layout();
00168     this->MapWindow();
00169 }

Generated on Mon Nov 23 05:26:56 2009 for loon by  doxygen 1.3.9.1