CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Fireworks/Core/src/FWPopupMenu.cc

Go to the documentation of this file.
00001 #include "TGMenu.h"
00002 #include "KeySymbols.h"
00003 
00004 class FWPopupMenu : public TGPopupMenu
00005 {
00006 public:
00007    FWPopupMenu(const TGWindow* p=0, UInt_t w=10, UInt_t h=10, UInt_t options=0) :
00008       TGPopupMenu(p, w, h, options)
00009    {
00010       AddInput(kKeyPressMask);
00011    }
00012 
00013    // virtual void      PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
00014    // {
00015    //    TGPopupMenu::PlaceMenu(x, y, stick_mode, grab_pointer);
00016    //    gVirtualX->GrabKey(fId, 0l, kAnyModifier, kTRUE);
00017    // }
00018 
00019    virtual void PoppedUp()
00020    {
00021       TGPopupMenu::PoppedUp();
00022       gVirtualX->SetInputFocus(fId);
00023       gVirtualX->GrabKey(fId, 0l, kAnyModifier, kTRUE);
00024       
00025    }
00026 
00027    virtual void PoppedDown()
00028    {
00029       gVirtualX->GrabKey(fId, 0l, kAnyModifier, kFALSE);
00030       TGPopupMenu::PoppedDown();
00031    }
00032 
00033    virtual Bool_t HandleKey(Event_t* event)
00034    {
00035       if (event->fType != kGKeyPress) return kTRUE;
00036 
00037       UInt_t keysym;
00038       char tmp[2];
00039       gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
00040 
00041       TGMenuEntry *ce = fCurrent;
00042 
00043       switch (keysym)
00044       {
00045          case kKey_Up:
00046          {
00047             if (ce) ce = (TGMenuEntry*)GetListOfEntries()->Before(ce);
00048             while (ce && ((ce->GetType() == kMenuSeparator) ||
00049                           (ce->GetType() == kMenuLabel) ||
00050                           !(ce->GetStatus() & kMenuEnableMask)))
00051             {
00052                ce = (TGMenuEntry*)GetListOfEntries()->Before(ce);
00053             }
00054             if (!ce) ce = (TGMenuEntry*)GetListOfEntries()->Last();
00055             Activate(ce);
00056             break;
00057          }
00058          case kKey_Down:
00059          {
00060             if (ce) ce = (TGMenuEntry*)GetListOfEntries()->After(ce);
00061             while (ce && ((ce->GetType() == kMenuSeparator) ||
00062                           (ce->GetType() == kMenuLabel) ||
00063                           !(ce->GetStatus() & kMenuEnableMask)))
00064             {
00065                ce = (TGMenuEntry*)GetListOfEntries()->After(ce);
00066             }
00067             if (!ce) ce = (TGMenuEntry*)GetListOfEntries()->First();
00068             Activate(ce);
00069             break;
00070          }
00071          case kKey_Enter:
00072          case kKey_Return:
00073          {
00074             Event_t ev;
00075             ev.fType = kButtonRelease;
00076             ev.fWindow = fId;
00077             return HandleButton(&ev);
00078          }
00079          case kKey_Escape:
00080          {
00081             fCurrent = 0;
00082             void *dummy = 0;
00083             return EndMenu(dummy);
00084          }
00085          default:
00086          {
00087             break;
00088          }
00089       }
00090 
00091       return kTRUE;
00092    }
00093 };