CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FWPopupMenu.cc
Go to the documentation of this file.
1 #include "TGMenu.h"
2 #include "KeySymbols.h"
3 #include "TVirtualX.h"
4 
5 class FWPopupMenu : public TGPopupMenu {
6 public:
7  FWPopupMenu(const TGWindow* p = nullptr, UInt_t w = 10, UInt_t h = 10, UInt_t options = 0)
8  : TGPopupMenu(p, w, h, options) {
9  AddInput(kKeyPressMask);
10  }
11 
12  // virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
13  // {
14  // TGPopupMenu::PlaceMenu(x, y, stick_mode, grab_pointer);
15  // gVirtualX->GrabKey(fId, 0l, kAnyModifier, kTRUE);
16  // }
17 
18  void PoppedUp() override {
19  TGPopupMenu::PoppedUp();
20  gVirtualX->SetInputFocus(fId);
21  gVirtualX->GrabKey(fId, 0l, kAnyModifier, kTRUE);
22  }
23 
24  void PoppedDown() override {
25  gVirtualX->GrabKey(fId, 0l, kAnyModifier, kFALSE);
26  TGPopupMenu::PoppedDown();
27  }
28 
29  Bool_t HandleKey(Event_t* event) override {
30  if (event->fType != kGKeyPress)
31  return kTRUE;
32 
33  UInt_t keysym;
34  char tmp[2];
35  gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
36 
37  TGMenuEntry* ce = fCurrent;
38 
39  switch (keysym) {
40  case kKey_Up: {
41  if (ce)
42  ce = (TGMenuEntry*)GetListOfEntries()->Before(ce);
43  while (ce && ((ce->GetType() == kMenuSeparator) || (ce->GetType() == kMenuLabel) ||
44  !(ce->GetStatus() & kMenuEnableMask))) {
45  ce = (TGMenuEntry*)GetListOfEntries()->Before(ce);
46  }
47  if (!ce)
48  ce = (TGMenuEntry*)GetListOfEntries()->Last();
49  Activate(ce);
50  break;
51  }
52  case kKey_Down: {
53  if (ce)
54  ce = (TGMenuEntry*)GetListOfEntries()->After(ce);
55  while (ce && ((ce->GetType() == kMenuSeparator) || (ce->GetType() == kMenuLabel) ||
56  !(ce->GetStatus() & kMenuEnableMask))) {
57  ce = (TGMenuEntry*)GetListOfEntries()->After(ce);
58  }
59  if (!ce)
60  ce = (TGMenuEntry*)GetListOfEntries()->First();
61  Activate(ce);
62  break;
63  }
64  case kKey_Enter:
65  case kKey_Return: {
66  Event_t ev;
67  ev.fType = kButtonRelease;
68  ev.fWindow = fId;
69  return HandleButton(&ev);
70  }
71  case kKey_Escape: {
72  fCurrent = nullptr;
73  void* dummy = nullptr;
74  return EndMenu(dummy);
75  }
76  default: {
77  break;
78  }
79  }
80 
81  return kTRUE;
82  }
83 };
void PoppedUp() override
Definition: FWPopupMenu.cc:18
const double w
Definition: UKUtility.cc:23
Bool_t HandleKey(Event_t *event) override
Definition: FWPopupMenu.cc:29
void PoppedDown() override
Definition: FWPopupMenu.cc:24
bool ev
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
tmp
align.sh
Definition: createJobs.py:716
FWPopupMenu(const TGWindow *p=nullptr, UInt_t w=10, UInt_t h=10, UInt_t options=0)
Definition: FWPopupMenu.cc:7