DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PopupMenu.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DDEve/PopupMenu.h"
17 #include "DD4hep/Printout.h"
18 #include "DD4hep/InstanceCount.h"
19 
20 // C/C++ include files
21 
22 // Forward declarations
23 
24 using namespace DD4hep;
25 
27 
28 PopupMenu::PopupMenu(const TGWindow *parent) : m_popup(parent), m_cmd(0) {
30  m_popup.Connect("Activated(int)", "DD4hep::PopupMenu", this, "HandleMenu(int)");
32 }
33 
36  m_popup.Disconnect("Activated(int)", this, "HandleMenu(int)");
37  m_calls.clear();
39 }
40 
42 void PopupMenu::Build(TGMenuBar* /* bar */, int /* hints */) {
43 }
44 
46 void PopupMenu::AddSeparator(TGMenuEntry* before) {
47  m_popup.AddSeparator(before);
48 }
49 
51 void PopupMenu::AddLabel(const char* s, const TGPicture* p, TGMenuEntry* before) {
52  m_popup.AddLabel(s,p,before);
53 }
54 
56 void PopupMenu::AddPopup(const char* s, TGPopupMenu* popup, TGMenuEntry* before, const TGPicture* p) {
57  m_popup.AddPopup(s,popup,before,p);
58 }
59 
61 int PopupMenu::AddEntry(const char* name, Callback cb, void* ud, const TGPicture* p, TGMenuEntry* before) {
62  m_calls[++m_cmd] = cb;
63  m_popup.AddEntry(name, m_cmd, ud, p, before);
64  return m_cmd;
65 }
66 
68 void PopupMenu::HandleMenu(int id) {
69  Callbacks::const_iterator i = m_calls.find(id);
70  if ( i != m_calls.end() ) {
71  TGMenuEntry* e = m_popup.GetEntry(id);
72  void* ud = e->GetUserData();
73  const void* args[2] = {&e, ud};
74  printout(INFO,"PopupMenu","+++ HandleMenu: executing callback with ID=%d Arg=%p [%p]",id,ud,&ud);
75  (*i).second.execute(args);
76  return;
77  }
78  printout(INFO,"PopupMenu","+++ HandleMenu: unhandled callback with ID=%d",id);
79 }
80 
82 void PopupMenu::CheckEntry(int id) {
83  m_popup.CheckEntry(id);
84 }
85 
88  m_popup.UnCheckEntry(id);
89 }
90 
93  return m_popup.IsEntryChecked(id);
94 }
95 
96 
void CheckEntry(int id)
Check menu entry.
Definition: PopupMenu.cpp:82
virtual void AddLabel(const char *s, const TGPicture *p=0, TGMenuEntry *before=0)
Add a menu label to the menu.
Definition: PopupMenu.cpp:51
virtual ~PopupMenu()
Default destructor.
Definition: PopupMenu.cpp:35
void HandleMenu(int id)
Handle menu items.
Definition: PopupMenu.cpp:68
static void decrement(T *)
Decrement count according to type information.
TGPopupMenu m_popup
Definition: PopupMenu.h:43
Callbacks m_calls
Callback map.
Definition: PopupMenu.h:42
virtual void AddPopup(const char *s, TGPopupMenu *popup, TGMenuEntry *before=0, const TGPicture *p=0)
Add a (cascading) popup menu to a popup menu.
Definition: PopupMenu.cpp:56
ClassImp(PopupMenu) PopupMenu
Standard constructor.
Definition: PopupMenu.cpp:26
TGeoShape * s
Definition: Volumes.cpp:294
void UnCheckEntry(int id)
Uncheck menu entry.
Definition: PopupMenu.cpp:87
return e
Definition: Volumes.cpp:297
virtual void AddSeparator(TGMenuEntry *before=0)
Add a menu separator to the menu.
Definition: PopupMenu.cpp:46
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:61
Definition of the generic callback structure for member functions.
Definition: Callback.h:38
bool IsEntryChecked(int id)
Get check-value.
Definition: PopupMenu.cpp:92
class PopupMenu PopupMenu.h DDEve/PopupMenu.h
Definition: PopupMenu.h:37
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
virtual void Build(TGMenuBar *bar, int hints=kLHintsNormal)
Add the menu to the menu bar.
Definition: PopupMenu.cpp:42