File indexing completed on 2024-04-06 12:11:42
0001 #include "TGMenu.h"
0002 #include "KeySymbols.h"
0003 #include "TVirtualX.h"
0004
0005 class FWPopupMenu : public TGPopupMenu {
0006 public:
0007 FWPopupMenu(const TGWindow* p = nullptr, UInt_t w = 10, UInt_t h = 10, UInt_t options = 0)
0008 : TGPopupMenu(p, w, h, options) {
0009 AddInput(kKeyPressMask);
0010 }
0011
0012
0013
0014
0015
0016
0017
0018 void PoppedUp() override {
0019 TGPopupMenu::PoppedUp();
0020 gVirtualX->SetInputFocus(fId);
0021 gVirtualX->GrabKey(fId, 0l, kAnyModifier, kTRUE);
0022 }
0023
0024 void PoppedDown() override {
0025 gVirtualX->GrabKey(fId, 0l, kAnyModifier, kFALSE);
0026 TGPopupMenu::PoppedDown();
0027 }
0028
0029 Bool_t HandleKey(Event_t* event) override {
0030 if (event->fType != kGKeyPress)
0031 return kTRUE;
0032
0033 UInt_t keysym;
0034 char tmp[2];
0035 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
0036
0037 TGMenuEntry* ce = fCurrent;
0038
0039 switch (keysym) {
0040 case kKey_Up: {
0041 if (ce)
0042 ce = (TGMenuEntry*)GetListOfEntries()->Before(ce);
0043 while (ce && ((ce->GetType() == kMenuSeparator) || (ce->GetType() == kMenuLabel) ||
0044 !(ce->GetStatus() & kMenuEnableMask))) {
0045 ce = (TGMenuEntry*)GetListOfEntries()->Before(ce);
0046 }
0047 if (!ce)
0048 ce = (TGMenuEntry*)GetListOfEntries()->Last();
0049 Activate(ce);
0050 break;
0051 }
0052 case kKey_Down: {
0053 if (ce)
0054 ce = (TGMenuEntry*)GetListOfEntries()->After(ce);
0055 while (ce && ((ce->GetType() == kMenuSeparator) || (ce->GetType() == kMenuLabel) ||
0056 !(ce->GetStatus() & kMenuEnableMask))) {
0057 ce = (TGMenuEntry*)GetListOfEntries()->After(ce);
0058 }
0059 if (!ce)
0060 ce = (TGMenuEntry*)GetListOfEntries()->First();
0061 Activate(ce);
0062 break;
0063 }
0064 case kKey_Enter:
0065 case kKey_Return: {
0066 Event_t ev;
0067 ev.fType = kButtonRelease;
0068 ev.fWindow = fId;
0069 return HandleButton(&ev);
0070 }
0071 case kKey_Escape: {
0072 fCurrent = nullptr;
0073 void* dummy = nullptr;
0074 return EndMenu(dummy);
0075 }
0076 default: {
0077 break;
0078 }
0079 }
0080
0081 return kTRUE;
0082 }
0083 };