WindowMenu.cxx
Go to the documentation of this file.
1 ///
2 /// \file WindowMenu.cxx
3 /// \brief Implement the pull down window menu
4 ///
5 /// \version $Id: WindowMenu.cxx,v 1.4 2011-07-11 19:35:05 brebel Exp $
6 /// \author messier@indiana.edu
7 ///
8 #include <cstdlib>
9 #include <string>
10 #include <iostream>
11 #include "TGMsgBox.h"
12 #include "TGMenu.h"
13 #include "TGLayout.h"
14 
15 #include "nutools/EventDisplayBase/WindowMenu.h"
16 #include "nutools/EventDisplayBase/evdb.h"
17 #include "nutools/EventDisplayBase/DisplayWindow.h"
18 #include "nutools/EventDisplayBase/ListWindow.h"
19 #include "nutools/EventDisplayBase/ScanWindow.h"
20 
21 namespace evdb{
22 
23 //......................................................................
24 
25  WindowMenu::WindowMenu(TGMenuBar* menubar, TGMainFrame* /*mf*/)
26  {
27  fWindowMenu = new TGPopupMenu(gClient->GetRoot());
28  fLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
29 
30  // Create the list of functions. Associate each which a command code
31  unsigned int cnt = 2;
32  unsigned int i=0;
33  const std::vector<std::string>& names = DisplayWindow::Names();
34  for (; i<names.size(); ++i) {
35  fWindowMenu->AddEntry(names[i].c_str(), cnt+i);
36  }
37  fWindowMenu->AddSeparator();
38 
39  // Create the list of functions. Associate each which a command code
40  const std::vector<std::string>& lnames = ListWindow::Names();
41  for (unsigned int j=0; j<lnames.size(); ++j) {
42  fWindowMenu->AddEntry(lnames[j].c_str(), cnt+i+j);
43  }
44  fWindowMenu->AddSeparator();
45  fWindowMenu->AddEntry("&Scan Window", 0);
46  fWindowMenu->AddSeparator();
47  //fWindowMenu->AddEntry("&MC Information", -2);
48  fWindowMenu->AddEntry("&ROOT Browser", 1);
49  fWindowMenu->Connect("Activated(Int_t)",
50  "evdb::WindowMenu",this,"HandleMenu(int)");
51 
52  // Attach the menu to the menu bar
53  menubar->AddPopup("&Window",fWindowMenu,fLayout);
54  }
55 
56  //......................................................................
57 
59  {
60  if (fLayout) { delete fLayout; fLayout = 0; }
61  if (fWindowMenu) { delete fWindowMenu; fWindowMenu = 0; }
62  }
63 
64  //......................................................................
65 
66  void WindowMenu::HandleMenu(int menu)
67  {
68  if( menu == 0 ){
69  new ScanWindow();
70  return;
71  }
72  //
73  // Check if the menu has selected one of the named "user" windows
74  //
75  if (menu-2 < (int)DisplayWindow::Names().size()) {
76  int aok = DisplayWindow::OpenWindow(menu-2);
77  if (aok<0) this->NoImpl("Error openning requested window");
78  return;
79  }
80  }
81 
82  //......................................................................
83 
84  int WindowMenu::NoImpl(const char* method)
85  {
86  std::string s;
87  s = "Sorry action '"; s += method; s+= "' is not implemented.\n";
88  // Why isn't this a memory leak? Dunno, but its seems the TG classes
89  // are all managed by TGClient which takes care of deletion
90  new TGMsgBox(evdb::TopWindow(),
92  "No implementation",s.c_str(),kMBIconExclamation);
93  return 0;
94  }
95 
96  //......................................................................
97 
99  {
100  new TGMsgBox(evdb::TopWindow(),
101  evdb::TopWindow(),
102  "Not for this view",
103  "This display does not implement a 3D viewer",
104  kMBIconExclamation);
105  return 0;
106  }
107 
108 } // namespace
109 ////////////////////////////////////////////////////////////////////////
std::string string
Definition: nybbler.cc:12
virtual ~WindowMenu()
Definition: WindowMenu.cxx:58
TGLayoutHints * fLayout
Definition: WindowMenu.h:35
Manage all things related to colors for the event display.
WindowMenu(TGMenuBar *menubar, TGMainFrame *mf)
Definition: WindowMenu.cxx:25
static int OpenWindow(int type=0)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
static const std::vector< std::string > & Names()
Definition: ListWindow.cxx:46
int NoImpl(const char *m)
Definition: WindowMenu.cxx:84
void HandleMenu(int menu)
Definition: WindowMenu.cxx:66
static const std::vector< std::string > & Names()
const TGWindow * TopWindow()
Definition: evdb.cxx:12
TGPopupMenu * fWindowMenu
Definition: WindowMenu.h:34
static QCString * s
Definition: config.cpp:1042