DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
PopupMenu.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DDEve/PopupMenu.h>
16 #include <DD4hep/Printout.h>
17 #include <DD4hep/InstanceCount.h>
18 
19 // C/C++ include files
20 
21 // Forward declarations
22 
23 using namespace dd4hep;
24 
26 
27 PopupMenu::PopupMenu(const TGWindow *parent) : m_popup(parent), m_cmd(0) {
29  m_popup.Connect("Activated(int)", "dd4hep::PopupMenu", this, "HandleMenu(int)");
30  InstanceCount::increment(this);
31 }
32 
34 PopupMenu::~PopupMenu() {
35  m_popup.Disconnect("Activated(int)", this, "HandleMenu(int)");
36  m_calls.clear();
38 }
39 
41 void PopupMenu::Build(TGMenuBar* /* bar */, int /* hints */) {
42 }
43 
45 void PopupMenu::AddSeparator(TGMenuEntry* before) {
46  m_popup.AddSeparator(before);
47 }
48 
50 void PopupMenu::AddLabel(const char* s, const TGPicture* p, TGMenuEntry* before) {
51  m_popup.AddLabel(s,p,before);
52 }
53 
55 void PopupMenu::AddPopup(const char* s, TGPopupMenu* popup, TGMenuEntry* before, const TGPicture* p) {
56  m_popup.AddPopup(s,popup,before,p);
57 }
58 
60 int PopupMenu::AddEntry(const char* name, Callback cb, void* ud, const TGPicture* p, TGMenuEntry* before) {
61  m_calls[++m_cmd] = cb;
62  m_popup.AddEntry(name, m_cmd, ud, p, before);
63  return m_cmd;
64 }
65 
67 void PopupMenu::HandleMenu(int id) {
68  Callbacks::const_iterator i = m_calls.find(id);
69  if ( i != m_calls.end() ) {
70  TGMenuEntry* e = m_popup.GetEntry(id);
71  void* ud = e->GetUserData();
72  const void* args[2] = {&e, ud};
73  printout(INFO,"PopupMenu","+++ HandleMenu: executing callback with ID=%d Arg=%p [%p]",id,ud,&ud);
74  (*i).second.execute(args);
75  return;
76  }
77  printout(INFO,"PopupMenu","+++ HandleMenu: unhandled callback with ID=%d",id);
78 }
79 
81 void PopupMenu::CheckEntry(int id) {
82  m_popup.CheckEntry(id);
83 }
84 
87  m_popup.UnCheckEntry(id);
88 }
89 
92  return m_popup.IsEntryChecked(id);
93 }
94 
95 
dd4hep::PopupMenu::m_cmd
int m_cmd
Definition: PopupMenu.h:43
ClassImp
ClassImp(PopupMenu) PopupMenu
Standard constructor.
Definition: PopupMenu.cpp:25
dd4hep::PopupMenu::HandleMenu
void HandleMenu(int id)
Handle menu items.
Definition: PopupMenu.cpp:67
dd4hep::PopupMenu::UnCheckEntry
void UnCheckEntry(int id)
Uncheck menu entry.
Definition: PopupMenu.cpp:86
dd4hep::PopupMenu::AddLabel
virtual void AddLabel(const char *label, const TGPicture *p=0, TGMenuEntry *before=0)
Add a menu label to the menu.
Definition: PopupMenu.cpp:50
dd4hep::PopupMenu::IsEntryChecked
bool IsEntryChecked(int id)
Get check-value.
Definition: PopupMenu.cpp:91
dd4hep::PopupMenu::CheckEntry
void CheckEntry(int id)
Check menu entry.
Definition: PopupMenu.cpp:81
dd4hep::Callback
Definition of the generic callback structure for member functions.
Definition: Callback.h:38
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
PopupMenu.h
dd4hep::PopupMenu::AddEntry
virtual int AddEntry(const char *name, Callback cb, void *ud=0, const TGPicture *p=0, TGMenuEntry *before=0)
Add a new popup menu entry with a callback.
Definition: PopupMenu.cpp:60
dd4hep::PopupMenu::m_calls
Callbacks m_calls
Callback map.
Definition: PopupMenu.h:41
dd4hep::PopupMenu
class PopupMenu PopupMenu.h DDEve/PopupMenu.h
Definition: PopupMenu.h:36
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::PopupMenu::AddSeparator
virtual void AddSeparator(TGMenuEntry *before=0)
Add a menu separator to the menu.
Definition: PopupMenu.cpp:45
dd4hep::PopupMenu::PopupMenu
PopupMenu(const TGWindow *parent)
Standard constructor.
dd4hep::PopupMenu::Build
virtual void Build(TGMenuBar *menuBar, int hints=kLHintsNormal)
Add the menu to the menu bar.
Definition: PopupMenu.cpp:41
InstanceCount.h
dd4hep::PopupMenu::AddPopup
virtual void AddPopup(const char *name, TGPopupMenu *popup, TGMenuEntry *before=0, const TGPicture *p=0)
Add a (cascading) popup menu to a popup menu.
Definition: PopupMenu.cpp:55
Printout.h
dd4hep::PopupMenu::m_popup
TGPopupMenu m_popup
Definition: PopupMenu.h:42