74 #include "RConfigure.h"
77 const TGGC *TGPopupMenu::fgDefaultGC = 0;
78 const TGGC *TGPopupMenu::fgDefaultSelectedGC = 0;
79 const TGGC *TGPopupMenu::fgDefaultSelectedBackgroundGC = 0;
80 const TGFont *TGPopupMenu::fgDefaultFont = 0;
81 const TGFont *TGPopupMenu::fgHilightFont = 0;
83 const TGGC *TGMenuTitle::fgDefaultGC = 0;
84 const TGGC *TGMenuTitle::fgDefaultSelectedGC = 0;
85 const TGFont *TGMenuTitle::fgDefaultFont = 0;
89 ClassImp(TGMenuTitle);
90 ClassImpQ(TGPopupMenu)
95 class TPopupDelayTimer : public TTimer {
99 TPopupDelayTimer(TGPopupMenu *p, Long_t ms) : TTimer(ms, kTRUE) { fPopup = p; }
106 Bool_t TPopupDelayTimer::Notify()
108 fPopup->HandleTimer(0);
123 TGMenuBar::TGMenuBar(
const TGWindow *p, UInt_t w, UInt_t h, UInt_t options)
124 : TGHorizontalFrame(p, w, h, options | kHorizontalFrame)
129 fDefaultCursor = fClient->GetResourcePool()->GetGrabCursor();
130 fTrash =
new TList();
132 gVirtualX->GrabButton(fId, kButton1, kAnyModifier,
133 kButtonPressMask | kButtonReleaseMask | kEnterWindowMask,
136 fKeyNavigate = kFALSE;
138 fMenuMore =
new TGPopupMenu(gClient->GetDefaultRoot());
139 fMenuMore->AddLabel(
"Hidden Menus");
140 fMenuMore->AddSeparator();
141 fMenuBarMoreLayout =
new TGLayoutHints(kLHintsTop | kLHintsRight);
144 fOutLayouts =
new TList();
145 fNeededSpace =
new TList();
152 TGMenuBar::~TGMenuBar()
158 if (!MustCleanup()) {
163 const TGMainFrame *main = (TGMainFrame *)GetMainFrame();
165 if (!MustCleanup()) {
167 while ((el = (TGFrameElement *) next())) {
168 t = (TGMenuTitle *) el->fFrame;
169 if ((keycode = t->GetHotKeyCode()) != 0 && main) {
170 main->RemoveBind(
this, keycode, kKeyMod1Mask);
176 if (fTitles && !MustCleanup()) fTitles->Delete();
180 fNeededSpace->Delete();
183 delete fMenuBarMoreLayout;
190 void TGMenuBar::Layout()
192 if (GetDefaultWidth() > GetWidth()) {
193 while (!(GetDefaultWidth() < GetWidth() ||
194 GetList()->GetSize() <= 1)) {
195 TGFrameElement* entry = GetLastOnLeft();
197 TGMenuTitle* menuTitle = (TGMenuTitle*) entry->fFrame;
198 fNeededSpace->AddLast(
new TParameter<Int_t>(
"", menuTitle->GetWidth() +
199 entry->fLayout->GetPadLeft() +
200 entry->fLayout->GetPadRight() ) );
201 fOutLayouts->AddLast( entry->fLayout );
202 fMenuMore->AddPopup( menuTitle->GetName(), menuTitle->GetMenu() );
203 menuTitle->GetMenu()->Connect(
"PoppedUp()",
"TGMenuBar",
this,
"PopupConnection()");
204 RemovePopup( menuTitle->GetName() );
208 if (fNeededSpace->GetSize() > 0) {
209 Int_t neededWidth = ((TParameter<Int_t>*) fNeededSpace->Last())->GetVal();
211 if (fNeededSpace->GetSize() > 1)
212 fit = GetDefaultWidth() + neededWidth + 5 < GetWidth();
214 fit = GetDefaultWidth() + neededWidth - 7 < GetWidth();
216 TGMenuEntry* menu = (TGMenuEntry*) fMenuMore->GetListOfEntries()->Last();
217 TGLayoutHints* layout = (TGLayoutHints*) fOutLayouts->Last();
218 ULong_t hints = (layout) ? layout->GetLayoutHints() : 0;
219 TGPopupMenu* beforeMenu = 0;
220 if (hints & kLHintsRight) {
221 TGFrameElement* entry = GetLastOnLeft();
223 TGMenuTitle* beforeMenuTitle = (TGMenuTitle*) entry->fFrame;
224 beforeMenu = beforeMenuTitle->GetMenu();
227 if (menu && menu->GetPopup()) {
228 menu->GetPopup()->Disconnect(
"PoppedUp()",
this,
"PopupConnection()");
229 AddPopup( menu->GetName(), menu->GetPopup(), layout, beforeMenu );
231 fOutLayouts->Remove( fOutLayouts->Last() );
232 fNeededSpace->Remove( fNeededSpace->Last() );
233 fMenuMore->DeleteEntry(menu);
235 if (fNeededSpace->GetSize() > 0) {
236 neededWidth = ((TParameter<Int_t>*)fNeededSpace->Last())->GetVal();
237 if (fNeededSpace->GetSize() > 1)
238 fit = GetDefaultWidth() + neededWidth + 5 < GetWidth();
240 fit = GetDefaultWidth() + neededWidth - 7 < GetWidth();
246 if (fNeededSpace->GetSize() > 0) {
248 AddPopup(
">>", fMenuMore, fMenuBarMoreLayout,
249 ((TGMenuTitle*)((TGFrameElement*)GetList()->First())->fFrame)->GetMenu());
258 TGHorizontalFrame::Layout();
265 TGFrameElement* TGMenuBar::GetLastOnLeft()
267 TIter next(GetList());
268 while (TGFrameElement *entry = (TGFrameElement*) next()) {
270 TGMenuTitle* menuTitle = (TGMenuTitle*) entry->fFrame;
271 TGLayoutHints* tmpLayout = (TGLayoutHints*) entry->fLayout;
272 ULong_t hints = tmpLayout->GetLayoutHints();
274 if (hints & kLHintsRight && menuTitle->GetMenu() != fMenuMore) {
279 return ((TGFrameElement*)GetList()->Last());
286 void TGMenuBar::PopupConnection()
289 TList* slots = fMenuMore->GetListOfSignals();
291 while (TList* connlist = (TList*) next()) {
293 const char* signal_name = connlist->GetName();
294 TIter next2(connlist);
295 while (TQConnection* conn = (TQConnection*) next2()) {
296 const char* slot_name = conn->GetName();
297 void* receiver = conn->GetReceiver();
298 fMenuMore->Disconnect(signal_name, receiver, slot_name);
301 fMenuMore->fMsgWindow = 0;
304 TGMenuEntry* currentEntry = fMenuMore->GetCurrent();
305 if (currentEntry->GetType() != kMenuPopup)
return;
308 TGPopupMenu* currentMenu = currentEntry->GetPopup();
310 slots = currentMenu->GetListOfSignals();
312 while (TList* connlist = (TList*) next3()) {
314 const char* signal_name = connlist->GetName();
315 if (strcmp(signal_name,
"Activated(int)") == 0) {
316 TIter next2(connlist);
317 while (TQConnection* conn = (TQConnection*) next2()) {
319 const char* slot_name = conn->GetName();
320 const char* class_name = conn->GetClassName();
321 void* receiver = conn->GetReceiver();
322 fMenuMore->Connect(signal_name, class_name, receiver, slot_name);
327 fMenuMore->fMsgWindow = currentMenu->fMsgWindow;
334 void TGMenuBar::BindKeys(Bool_t on)
336 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Left), kAnyModifier, on);
337 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Right), kAnyModifier, on);
338 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Up), kAnyModifier, on);
339 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Down), kAnyModifier, on);
340 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Enter), kAnyModifier, on);
341 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Return), kAnyModifier, on);
342 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Escape), kAnyModifier, on);
344 if (fCurrent && fCurrent->GetMenu()) {
345 BindMenu(fCurrent->GetMenu(), on);
352 void TGMenuBar::BindMenu(TGPopupMenu* subMenu, Bool_t on)
355 TIter next(subMenu->GetListOfEntries());
357 while ((e = (TGMenuEntry*)next())) {
359 if ( e->GetType() == kMenuPopup )
360 BindMenu(e->GetPopup(), on);
362 hot = e->GetLabel()->GetHotChar();
365 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), 0, on);
366 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask, on);
367 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask, on);
368 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyMod2Mask, on);
369 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask, on);
370 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyMod2Mask, on);
371 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask | kKeyMod2Mask, on);
372 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask | kKeyMod2Mask, on);
380 void TGMenuBar::BindHotKey(Int_t keycode, Bool_t on)
382 const TGMainFrame *main = (TGMainFrame *) GetMainFrame();
384 if (!main || !main->InheritsFrom(
"TGMainFrame"))
return;
388 main->BindKey(
this, keycode, kKeyMod1Mask);
389 main->BindKey(
this, keycode, kKeyMod1Mask | kKeyShiftMask);
390 main->BindKey(
this, keycode, kKeyMod1Mask | kKeyLockMask);
391 main->BindKey(
this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
393 main->BindKey(
this, keycode, kKeyMod1Mask | kKeyMod2Mask);
394 main->BindKey(
this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
395 main->BindKey(
this, keycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
396 main->BindKey(
this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
398 main->RemoveBind(
this, keycode, kKeyMod1Mask);
399 main->RemoveBind(
this, keycode, kKeyMod1Mask | kKeyShiftMask);
400 main->RemoveBind(
this, keycode, kKeyMod1Mask | kKeyLockMask);
401 main->RemoveBind(
this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
403 main->RemoveBind(
this, keycode, kKeyMod1Mask | kKeyMod2Mask);
404 main->RemoveBind(
this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
405 main->RemoveBind(
this, keycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
406 main->RemoveBind(
this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
415 void TGMenuBar::AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l,
421 AddFrameBefore(t =
new TGMenuTitle(
this, s, menu), l, before);
424 if ((keycode = t->GetHotKeyCode()) != 0) {
425 BindHotKey(keycode, kTRUE);
432 void TGMenuBar::AddTitle(TGMenuTitle *title, TGLayoutHints *l, TGPopupMenu *before)
436 AddFrameBefore(title, l, before);
439 if ((keycode = title->GetHotKeyCode()) != 0) {
440 BindHotKey(keycode, kTRUE);
448 void TGMenuBar::AddPopup(
const char *s, TGPopupMenu *menu, TGLayoutHints *l,
451 AddPopup(
new TGHotString(s), menu, l, before);
474 TGPopupMenu *TGMenuBar::AddPopup(
const TString &s, Int_t padleft, Int_t padright,
475 Int_t padtop, Int_t padbottom)
477 ULong_t hints = kLHintsTop;
480 hints |= kLHintsLeft;
482 hints |= kLHintsRight;
485 TGLayoutHints *l =
new TGLayoutHints(hints, padleft, padright,
489 TGPopupMenu *menu =
new TGPopupMenu(fClient->GetDefaultRoot());
490 AddPopup(
new TGHotString(s), menu, l, 0);
500 void TGMenuBar::AddFrameBefore(TGFrame *f, TGLayoutHints *l,
503 if (!f->InheritsFrom(
"TGMenuTitle")) {
504 Error(
"AddFrameBefore",
"may only add TGMenuTitle objects to a menu bar");
515 nw =
new TGFrameElement;
517 nw->fLayout = l ? l : fgDefaultHints;
522 while ((el = (TGFrameElement *) next())) {
523 TGMenuTitle *t = (TGMenuTitle *) el->fFrame;
524 if (t->GetMenu() == before) {
525 fList->AddBefore(el, nw);
537 TGPopupMenu *TGMenuBar::GetPopup(
const char *s)
539 if (!GetList())
return 0;
542 TIter next(GetList());
545 while ((el = (TGFrameElement *) next())) {
546 TGMenuTitle *t = (TGMenuTitle *) el->fFrame;
547 if (str == t->GetName())
558 TGPopupMenu *TGMenuBar::RemovePopup(
const char *s)
560 if (!GetList())
return 0;
563 TIter next(GetList());
566 while ((el = (TGFrameElement *) next())) {
567 TGMenuTitle *t = (TGMenuTitle *) el->fFrame;
568 if (str == t->GetName()) {
570 if ((keycode = t->GetHotKeyCode())) {
571 BindHotKey(keycode, kFALSE);
573 TGPopupMenu *m = t->GetMenu();
587 Bool_t TGMenuBar::HandleMotion(Event_t *event)
589 if (fKeyNavigate)
return kTRUE;
593 TGMenuTitle *target = 0;
595 if (!(event->fState & kButton1Mask))
598 gVirtualX->TranslateCoordinates(fId, fId, event->fX, event->fY,
599 dummy, dummy, wtarget);
600 if (wtarget) target = (TGMenuTitle*) fClient->GetWindowById(wtarget);
602 if (fCurrent && target && (target != fCurrent)) {
606 while ((el = (TGFrameElement *) next()))
607 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
611 target->SetState(kTRUE);
620 Bool_t TGMenuBar::HandleButton(Event_t *event)
629 if (event->fType == kButtonPress) {
631 gVirtualX->TranslateCoordinates(fId, fId, event->fX, event->fY,
632 dummy, dummy, wtarget);
633 target = (TGMenuTitle*) fClient->GetWindowById(wtarget);
638 if (target != fCurrent) {
642 while ((el = (TGFrameElement *) next()))
643 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
647 target->SetState(kTRUE);
649 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
650 kPointerMotionMask, kNone, fDefaultCursor);
655 if (event->fType == kButtonRelease) {
663 while ((el = (TGFrameElement *) next()))
664 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
666 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
672 target->DoSendMessage();
674 fKeyNavigate = kFALSE;
683 Bool_t TGMenuBar::HandleKey(Event_t *event)
685 TGMenuTitle *target = 0;
692 if (event->fType == kGKeyPress) {
696 gVirtualX->LookupString(event, tmp,
sizeof(tmp), keysym);
698 if (event->fState & kKeyMod1Mask) {
699 while ((el = (TGFrameElement *) next())) {
700 target = (TGMenuTitle *) el->fFrame;
701 if ((Int_t)
event->fCode == target->GetHotKeyCode()) {
703 fKeyNavigate = kTRUE;
707 if (el == 0) target = 0;
709 fKeyNavigate = kTRUE;
712 TGFrameElement *cur = 0;
713 TGPopupMenu *menu = 0;
716 while ((el = (TGFrameElement *) next())) {
717 if (el->fFrame == fCurrent) {
719 menu = ((TGMenuTitle*)el->fFrame)->GetMenu();
724 if (!menu || !menu->fPoppedUp)
return kFALSE;
728 TGPopupMenu* currentMenu = fCurrent->GetMenu();
729 TGMenuEntry* currentEntry = currentMenu->GetCurrent();
730 while ( currentEntry ) {
731 if ( currentEntry->GetType() == kMenuPopup )
732 currentMenu = currentEntry->GetPopup();
733 if ( currentEntry != currentMenu->GetCurrent() )
734 currentEntry = currentMenu->GetCurrent();
739 TIter next2(currentMenu->GetListOfEntries());
741 while ((ce = (TGMenuEntry*)next2())) {
743 if (ce->GetLabel()) hot = ce->GetLabel()->GetHotChar();
744 if (!hot || (hot != keysym))
continue;
746 currentMenu->Activate(ce);
747 if (ce->GetType() != kMenuPopup) {
748 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
749 fCurrent->SetState(kFALSE);
750 currentMenu->fStick = kFALSE;
752 ev.fType = kButtonRelease;
753 ev.fWindow = currentMenu->GetId();
755 return currentMenu->HandleButton(&ev);
758 gVirtualX->TranslateCoordinates(currentMenu->fId,
759 (ce->fPopup->GetParent())->GetId(),
760 ce->fEx+currentMenu->fMenuWidth, ce->fEy,
763 gVirtualX->SetWMTransientHint(ce->fPopup->GetId(), GetId());
765 ce->fPopup->PlaceMenu(ax-5, ay-1, kFALSE, kFALSE);
769 ce = menu->GetCurrent();
770 TGPopupMenu *submenu = 0;
772 while (ce && (ce->GetType() == kMenuPopup)) {
773 submenu = ce->GetPopup();
774 if (!submenu->fPoppedUp)
break;
775 ce = submenu->GetCurrent();
778 switch ((EKeySym)keysym) {
780 if ((submenu) && (submenu->fPoppedUp)) {
781 submenu->EndMenu(dummy);
784 el = (TGFrameElement*)fList->Before(cur);
785 if (!el) el = (TGFrameElement*)fList->Last();
789 if (submenu->fPoppedUp) {
790 if (!submenu->GetCurrent()) {
791 ce = (TGMenuEntry*)submenu->GetListOfEntries()->First();
793 submenu->EndMenu(dummy);
797 gVirtualX->TranslateCoordinates(menu->fId,
798 (submenu->GetParent())->GetId(),
799 ce->fEx+menu->fMenuWidth, ce->fEy,
802 gVirtualX->SetWMTransientHint(submenu->GetId(), GetId());
804 submenu->PlaceMenu(ax-5, ay-1, kFALSE, kFALSE);
808 el = (TGFrameElement*)fList->After(cur);
809 if (!el) el = (TGFrameElement*)fList->First();
812 if (ce) ce = (TGMenuEntry*)menu->GetListOfEntries()->Before(ce);
813 while (ce && ((ce->GetType() == kMenuSeparator) ||
814 (ce->GetType() == kMenuLabel) ||
815 !(ce->GetStatus() & kMenuEnableMask))) {
816 ce = (TGMenuEntry*)menu->GetListOfEntries()->Before(ce);
818 if (!ce) ce = (TGMenuEntry*)menu->GetListOfEntries()->Last();
821 if (ce) ce = (TGMenuEntry*)menu->GetListOfEntries()->After(ce);
822 while (ce && ((ce->GetType() == kMenuSeparator) ||
823 (ce->GetType() == kMenuLabel) ||
824 !(ce->GetStatus() & kMenuEnableMask))) {
825 ce = (TGMenuEntry*)menu->GetListOfEntries()->After(ce);
827 if (!ce) ce = (TGMenuEntry*)menu->GetListOfEntries()->First();
831 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
832 fCurrent->SetState(kFALSE);
833 menu->fStick = kFALSE;
835 ev.fType = kButtonRelease;
836 ev.fWindow = menu->GetId();
838 return menu->HandleButton(&ev);
841 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
842 fCurrent->SetState(kFALSE);
845 return menu->EndMenu(dummy);
849 if (ce) menu->Activate(ce);
852 if (el) target = (TGMenuTitle*)el->fFrame;
861 if (target != fCurrent) {
864 while ((el = (TGFrameElement *) next()))
865 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
868 target->SetState(kTRUE);
871 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
872 kPointerMotionMask, kNone, fDefaultCursor);
875 TIter nexte(target->GetMenu()->GetListOfEntries());
877 while ((ptr = (TGMenuEntry *) nexte())) {
878 if ((ptr->GetStatus() & kMenuEnableMask) &&
879 !(ptr->GetStatus() & kMenuHideMask) &&
880 (ptr->GetType() != kMenuSeparator) &&
881 (ptr->GetType() != kMenuLabel))
break;
884 target->GetMenu()->Activate(ptr);
893 if (event->fType == kKeyRelease) {
898 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
901 while ((el = (TGFrameElement *) next()))
902 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
907 target->DoSendMessage();
924 TGPopupMenu::TGPopupMenu(
const TGWindow *p, UInt_t w, UInt_t h, UInt_t options)
925 : TGFrame(p, w, h, options | kOwnBackground)
927 fNormGC = GetDefaultGC()();
928 fSelGC = GetDefaultSelectedGC()();
929 fSelbackGC = GetDefaultSelectedBackgroundGC()();
930 fFontStruct = GetDefaultFontStruct();
931 fHifontStruct = GetHilightFontStruct();
932 fDefaultCursor = fClient->GetResourcePool()->GetGrabCursor();
937 gcval.fMask = kGCFont;
938 gcval.fFont = gVirtualX->GetFontHandle(fFontStruct);
939 gVirtualX->ChangeGC(fNormGC, &gcval);
940 gVirtualX->ChangeGC(fSelGC, &gcval);
943 fEntryList =
new TList;
959 SetWindowAttributes_t wattr;
960 wattr.fMask = kWAOverrideRedirect | kWASaveUnder;
961 wattr.fOverrideRedirect = kTRUE;
962 wattr.fSaveUnder = kTRUE;
964 gVirtualX->ChangeWindowAttributes(fId, &wattr);
966 AddInput(kPointerMotionMask | kEnterWindowMask | kLeaveWindowMask);
972 TGPopupMenu::~TGPopupMenu()
974 gClient->UnregisterPopup(
this);
976 if (fEntryList) fEntryList->Delete();
987 void TGPopupMenu::AddEntry(TGHotString *s, Int_t
id,
void *ud,
988 const TGPicture *p, TGMenuEntry *before)
991 TGMenuEntry *nw =
new TGMenuEntry;
992 Ssiz_t tab = s->Index(
'\t');
994 TString ts(s->Data());
995 TString shortcut = ts(tab+1, s->Length());
996 nw->fShortcut =
new TGString(shortcut.Data());
997 nw->fLabel =
new TGHotString(*s);
998 nw->fLabel->Remove(tab);
1004 nw->fType = kMenuEntry;
1008 nw->fStatus = kMenuEnableMask;
1010 nw->fEy = fMenuHeight-2;
1013 fEntryList->AddBefore(before, nw);
1015 fEntryList->Add(nw);
1017 UInt_t tw, ph = 0, pw = 0;
1018 tw = gVirtualX->TextWidth(fHifontStruct, s->GetString(), s->GetLength());
1020 ph = p->GetHeight();
1022 if (pw+12 > fXl) { fMenuWidth += pw+12-fXl; fXl = pw+12; }
1024 if (nw->fShortcut) {
1029 Int_t max_ascent, max_descent;
1030 nw->fEw = tw + pw +18+12;
1031 fMenuWidth = TMath::Max(fMenuWidth, nw->fEw);
1032 gVirtualX->GetFontProperties(fHifontStruct, max_ascent, max_descent);
1033 nw->fEh = max_ascent + max_descent + fEntrySep;
1034 if (nw->fEh < ph+fEntrySep) nw->fEh = ph+fEntrySep;
1035 fMenuHeight += nw->fEh;
1040 Resize(fMenuWidth, fMenuHeight);
1047 void TGPopupMenu::AddEntry(
const char *s, Int_t
id,
void *ud,
1048 const TGPicture *p, TGMenuEntry *before)
1050 AddEntry(
new TGHotString(s),
id, ud, p, before);
1057 void TGPopupMenu::AddSeparator(TGMenuEntry *before)
1059 TGMenuEntry *nw =
new TGMenuEntry;
1063 nw->fType = kMenuSeparator;
1067 nw->fStatus = kMenuEnableMask;
1069 nw->fEy = fMenuHeight-2;
1072 fEntryList->AddBefore(before, nw);
1074 fEntryList->Add(nw);
1078 fMenuHeight += nw->fEh;
1083 Resize(fMenuWidth, fMenuHeight);
1092 void TGPopupMenu::AddLabel(TGHotString *s,
const TGPicture *p,
1093 TGMenuEntry *before)
1095 TGMenuEntry *nw =
new TGMenuEntry;
1099 nw->fType = kMenuLabel;
1103 nw->fStatus = kMenuEnableMask | kMenuDefaultMask;
1105 nw->fEy = fMenuHeight-2;
1108 fEntryList->AddBefore(before, nw);
1110 fEntryList->Add(nw);
1112 UInt_t tw, ph = 0, pw = 0;
1113 tw = gVirtualX->TextWidth(fHifontStruct, s->GetString(), s->GetLength());
1115 ph = p->GetHeight();
1117 if (pw+12 > fXl) { fMenuWidth += pw+12-fXl; fXl = pw+12; }
1120 Int_t max_ascent, max_descent;
1121 nw->fEw = tw + pw +18+12;
1122 fMenuWidth = TMath::Max(fMenuWidth, nw->fEw);
1123 gVirtualX->GetFontProperties(fHifontStruct, max_ascent, max_descent);
1124 nw->fEh = max_ascent + max_descent + fEntrySep;
1125 if (nw->fEh < ph+fEntrySep) nw->fEh = ph+fEntrySep;
1126 fMenuHeight += nw->fEh;
1131 Resize(fMenuWidth, fMenuHeight);
1138 void TGPopupMenu::AddLabel(
const char *s,
const TGPicture *p,
1139 TGMenuEntry *before)
1141 AddLabel(
new TGHotString(s), p, before);
1149 void TGPopupMenu::AddPopup(TGHotString *s, TGPopupMenu *popup,
1150 TGMenuEntry *before,
const TGPicture *p)
1152 TGMenuEntry *nw =
new TGMenuEntry;
1156 nw->fType = kMenuPopup;
1160 nw->fStatus = kMenuEnableMask;
1162 nw->fEy = fMenuHeight-2;
1165 fEntryList->AddBefore(before, nw);
1167 fEntryList->Add(nw);
1169 UInt_t tw = gVirtualX->TextWidth(fHifontStruct, s->GetString(),
1172 UInt_t ph = 0, pw = 8;
1174 ph = p->GetHeight();
1176 if (pw+12 > fXl) { fMenuWidth += pw+12-fXl; fXl = pw+12; }
1178 Int_t max_ascent, max_descent;
1179 nw->fEw = tw + pw+18+12;
1180 fMenuWidth = TMath::Max(fMenuWidth, nw->fEw);
1181 gVirtualX->GetFontProperties(fHifontStruct, max_ascent, max_descent);
1182 nw->fEh = max_ascent + max_descent + fEntrySep;
1183 if (nw->fEh < ph+fEntrySep) nw->fEh = ph+fEntrySep;
1184 fMenuHeight += nw->fEh;
1189 Resize(fMenuWidth, fMenuHeight);
1196 void TGPopupMenu::AddPopup(
const char *s, TGPopupMenu *popup,
1197 TGMenuEntry *before,
const TGPicture *p)
1199 AddPopup(
new TGHotString(s), popup, before, p);
1206 void TGPopupMenu::Reposition()
1214 TIter next(fEntryList);
1216 while ((ptr = (TGMenuEntry *) next())) {
1218 if (ptr->fStatus & kMenuHideMask)
continue;
1221 UInt_t pw = ptr->fPic->GetWidth();
1222 if (pw+12 > fXl) { fMenuWidth += pw+12-fXl; fXl = pw+12; }
1225 ptr->fEy = fMenuHeight-2;
1226 fMenuWidth = TMath::Max(fMenuWidth, ptr->fEw);
1227 fMenuHeight += ptr->fEh;
1229 Resize(fMenuWidth, fMenuHeight);
1238 void TGPopupMenu::PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
1246 fStick = stick_mode;
1250 gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);
1252 if (gVirtualX->InheritsFrom(
"TGWin32")) {
1253 if ((x > 0) && ((x + abs(rx) + (Int_t)fMenuWidth) > (Int_t)rw))
1254 x = rw - abs(rx) - fMenuWidth;
1255 if ((y > 0) && (y + abs(ry) + (Int_t)fMenuHeight > (Int_t)rh))
1256 y = rh - fMenuHeight;
1259 if (x + fMenuWidth > rw) x = rw - fMenuWidth;
1261 if (y + fMenuHeight > rh) y = rh - fMenuHeight;
1268 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
1269 kPointerMotionMask, kNone, fDefaultCursor);
1277 if (fMenuBar) fMenuBar->BindKeys(kTRUE);
1279 fClient->RegisterPopup(
this);
1286 Int_t TGPopupMenu::EndMenu(
void *&userData)
1290 if (fDelay) fDelay->Remove();
1294 if (fCurrent != 0) {
1297 fCurrent->fStatus &= ~kMenuActiveMask;
1299 if ((fCurrent->fType == kMenuPopup) && fCurrent->fPopup) {
1300 id = fCurrent->fPopup->EndMenu(userData);
1303 if (fCurrent->fStatus & kMenuEnableMask) {
1304 id = fCurrent->fEntryId;
1305 userData = fCurrent->fUserData;
1321 gClient->UnregisterPopup(
this);
1322 if (fMenuBar) fMenuBar->BindKeys(kFALSE);
1335 Bool_t TGPopupMenu::HandleButton(Event_t *event)
1340 if (event->fType == kButtonRelease) {
1348 if (fHasGrab) gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
1349 if (fCurrent != 0) {
1350 fCurrent->fStatus &= ~kMenuActiveMask;
1351 if (fCurrent->fStatus & kMenuEnableMask) {
1352 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_MENU),
id,
1364 Bool_t TGPopupMenu::HandleCrossing(Event_t *event)
1366 if (event->fType == kEnterNotify) {
1369 TIter next(fEntryList);
1371 while ((ptr = (TGMenuEntry *) next())) {
1372 if (ptr->fStatus & kMenuHideMask)
continue;
1374 if ((event->fX >= ptr->fEx) && (event->fX <= ptr->fEx+(Int_t)fMenuWidth-10) &&
1375 (event->fY >= ptr->fEy) && (event->fY <= ptr->fEy+(Int_t)ptr->fEh))
1380 Activate((TGMenuEntry*)0);
1382 if (fMenuBar) fMenuBar->fKeyNavigate = kFALSE;
1383 if (fSplitButton) fSplitButton->fKeyNavigate = kFALSE;
1391 Bool_t TGPopupMenu::HandleMotion(Event_t *event)
1393 TGFrame::HandleMotion(event);
1394 static Int_t twice = 0;
1396 TIter next(fEntryList);
1407 while ((ptr = (TGMenuEntry *) next())) {
1408 if (ptr->fStatus & kMenuHideMask)
continue;
1410 if ((event->fX >= ptr->fEx) && (event->fX <= ptr->fEx+(Int_t)fMenuWidth-4) &&
1411 (event->fY >= ptr->fEy) && (event->fY <= ptr->fEy+(Int_t)ptr->fEh))
1422 void TGPopupMenu::Activate(TGMenuEntry *entry)
1424 if (entry == fCurrent)
return;
1428 if (fCurrent != 0) {
1430 if (entry == 0 && fCurrent->fType == kMenuPopup)
return;
1431 if ((fCurrent->fType == kMenuPopup) && fCurrent->fPopup)
1432 fCurrent->fPopup->EndMenu(ud);
1433 fCurrent->fStatus &= ~kMenuActiveMask;
1434 DrawEntry(fCurrent);
1437 if (fDelay) fDelay->Remove();
1442 entry->fStatus |= kMenuActiveMask;
1444 if (entry->fType == kMenuPopup) {
1445 if (!fDelay) fDelay =
new TPopupDelayTimer(
this, 350);
1447 gSystem->AddTimer(fDelay);
1450 }
else if (entry->fType == kMenuEntry) {
1452 SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_MENUSELECT),
1453 entry->fEntryId, (Long_t)entry->fUserData);
1454 Highlighted(entry->fEntryId);
1464 Bool_t TGPopupMenu::HandleTimer(TTimer *)
1466 if (fCurrent != 0) {
1467 if ((fCurrent->fType == kMenuPopup) && fCurrent->fPopup) {
1471 gVirtualX->TranslateCoordinates(fId,
1472 (fCurrent->fPopup->GetParent())->GetId(),
1473 fCurrent->fEx+fMenuWidth, fCurrent->fEy,
1476 gVirtualX->SetWMTransientHint(fCurrent->fPopup->GetId(), GetId());
1478 fCurrent->fPopup->PlaceMenu(ax-5, ay-1, kFALSE, kFALSE);
1489 void TGPopupMenu::DoRedraw()
1491 TGFrame::DoRedraw();
1494 TIter next(fEntryList);
1496 while ((ptr = (TGMenuEntry *) next()))
1503 void TGPopupMenu::DrawEntry(TGMenuEntry *entry)
1508 if (entry->fStatus & kMenuHideMask)
1511 if (entry->fStatus & kMenuDefaultMask) {
1512 font = fHifontStruct;
1513 gcval.fMask = kGCFont;
1514 gcval.fFont = gVirtualX->GetFontHandle(font);
1515 gVirtualX->ChangeGC(fNormGC, &gcval);
1516 gVirtualX->ChangeGC(fSelGC, &gcval);
1522 int max_ascent, max_descent;
1523 gVirtualX->GetFontProperties(font, max_ascent, max_descent);
1524 int tx = entry->fEx + fXl;
1526 int offset = (entry->fEh - (max_ascent + max_descent)) / 2;
1527 int ty = entry->fEy + max_ascent + offset - 1;
1528 if (entry->fShortcut)
1529 tw = 7 + gVirtualX->TextWidth(fFontStruct, entry->fShortcut->Data(), entry->fShortcut->Length());
1531 switch (entry->fType) {
1535 if ((entry->fStatus & kMenuActiveMask) && entry->fType != kMenuLabel) {
1536 gVirtualX->FillRectangle(fId, fSelbackGC, entry->fEx+1, entry->fEy-1,
1537 fMenuWidth-6, entry->fEh);
1538 if (gClient->GetStyle() > 1)
1539 gVirtualX->DrawRectangle(fId, GetShadowGC()(), entry->fEx+1, entry->fEy-2,
1540 fMenuWidth-7, entry->fEh);
1541 if (entry->fType == kMenuPopup)
1542 DrawTrianglePattern(fSelGC, fMenuWidth-10, entry->fEy+fEntrySep, fMenuWidth-6, entry->fEy+11);
1543 if (entry->fStatus & kMenuCheckedMask)
1544 DrawCheckMark(fSelGC, 6, entry->fEy+fEntrySep, 14, entry->fEy+11);
1545 if (entry->fStatus & kMenuRadioMask)
1546 DrawRCheckMark(fSelGC, 6, entry->fEy+fEntrySep, 14, entry->fEy+11);
1547 if (entry->fPic != 0)
1548 entry->fPic->Draw(fId, fSelGC, 8, entry->fEy+1);
1549 entry->fLabel->Draw(fId,
1550 (entry->fStatus & kMenuEnableMask) ? fSelGC : GetShadowGC()(),
1552 if (entry->fShortcut)
1553 entry->fShortcut->Draw(fId, (entry->fStatus & kMenuEnableMask) ? fSelGC : GetShadowGC()(),
1554 fMenuWidth - tw, ty);
1556 if (gClient->GetStyle() > 1)
1557 gVirtualX->DrawRectangle(fId, GetBckgndGC()(), entry->fEx+1, entry->fEy-2,
1558 fMenuWidth-7, entry->fEh);
1559 gVirtualX->FillRectangle(fId, GetBckgndGC()(), entry->fEx+1, entry->fEy-1,
1560 fMenuWidth-6, entry->fEh);
1561 if (entry->fType == kMenuPopup)
1562 DrawTrianglePattern(fNormGC, fMenuWidth-10, entry->fEy+fEntrySep, fMenuWidth-6, entry->fEy+11);
1563 if (entry->fStatus & kMenuCheckedMask)
1564 DrawCheckMark(fNormGC, 6, entry->fEy+fEntrySep, 14, entry->fEy+11);
1565 if (entry->fStatus & kMenuRadioMask)
1566 DrawRCheckMark(fNormGC, 6, entry->fEy+fEntrySep, 14, entry->fEy+11);
1567 if (entry->fPic != 0)
1568 entry->fPic->Draw(fId, fNormGC, 8, entry->fEy+1);
1569 if (entry->fStatus & kMenuEnableMask) {
1570 entry->fLabel->Draw(fId, fNormGC, tx, ty);
1571 if (entry->fShortcut)
1572 entry->fShortcut->Draw(fId, fNormGC, fMenuWidth - tw, ty);
1574 entry->fLabel->Draw(fId, GetHilightGC()(), tx+1, ty+1);
1575 entry->fLabel->Draw(fId, GetShadowGC()(), tx, ty);
1576 if (entry->fShortcut) {
1577 entry->fShortcut->Draw(fId, GetHilightGC()(), fMenuWidth - tw+1, ty+1);
1578 entry->fShortcut->Draw(fId, GetShadowGC()(), fMenuWidth - tw, ty);
1584 case kMenuSeparator:
1585 gVirtualX->DrawLine(fId, GetShadowGC()(), 2, entry->fEy, fMenuWidth-fEntrySep, entry->fEy);
1586 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, entry->fEy+1, fMenuWidth-fEntrySep, entry->fEy+1);
1591 if (entry->fStatus & kMenuDefaultMask) {
1592 gcval.fFont = gVirtualX->GetFontHandle(fFontStruct);
1593 gVirtualX->ChangeGC(fNormGC, &gcval);
1594 gVirtualX->ChangeGC(fSelGC, &gcval);
1601 void TGPopupMenu::DrawBorder()
1603 if (gClient->GetStyle() > 0) {
1605 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fMenuHeight-1);
1606 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, fMenuHeight-1, fMenuWidth-1, fMenuHeight-1);
1607 gVirtualX->DrawLine(fId, GetShadowGC()(), fMenuWidth-1, fMenuHeight-1, fMenuWidth-1, 0);
1608 gVirtualX->DrawLine(fId, GetShadowGC()(), fMenuWidth-1, 0, 0, 0);
1612 gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, fMenuWidth-2, 0);
1613 gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, 0, fMenuHeight-2);
1614 gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, fMenuWidth-fEntrySep, 1);
1615 gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, 1, fMenuHeight-fEntrySep);
1617 gVirtualX->DrawLine(fId, GetShadowGC()(), 1, fMenuHeight-2, fMenuWidth-2, fMenuHeight-2);
1618 gVirtualX->DrawLine(fId, GetShadowGC()(), fMenuWidth-2, fMenuHeight-2, fMenuWidth-2, 1);
1619 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, fMenuHeight-1, fMenuWidth-1, fMenuHeight-1);
1620 gVirtualX->DrawLine(fId, GetBlackGC()(), fMenuWidth-1, fMenuHeight-1, fMenuWidth-1, 0);
1628 void TGPopupMenu::DrawTrianglePattern(GContext_t gc, Int_t l, Int_t t,
1633 int m = (t + b) >> 1;
1642 gVirtualX->FillPolygon(fId, gc, points, 3);
1648 void TGPopupMenu::DrawCheckMark(GContext_t gc, Int_t l, Int_t t, Int_t, Int_t b)
1652 t = (t + b - 8) >> 1; ++t;
1654 seg[0].fX1 = 1+l; seg[0].fY1 = 3+t; seg[0].fX2 = 3+l; seg[0].fY2 = 5+t;
1655 seg[1].fX1 = 1+l; seg[1].fY1 = 4+t; seg[1].fX2 = 3+l; seg[1].fY2 = 6+t;
1656 seg[2].fX1 = 1+l; seg[2].fY1 = 5+t; seg[2].fX2 = 3+l; seg[2].fY2 = 7+t;
1657 seg[3].fX1 = 3+l; seg[3].fY1 = 5+t; seg[3].fX2 = 7+l; seg[3].fY2 = 1+t;
1658 seg[4].fX1 = 3+l; seg[4].fY1 = 6+t; seg[4].fX2 = 7+l; seg[4].fY2 = 2+t;
1659 seg[5].fX1 = 3+l; seg[5].fY1 = 7+t; seg[5].fX2 = 7+l; seg[5].fY2 = 3+t;
1661 gVirtualX->DrawSegments(fId, gc, seg, 6);
1667 void TGPopupMenu::DrawRCheckMark(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b)
1671 t = (t + b - 5) >> 1; ++t;
1672 l = (l + r - 5) >> 1; ++l;
1674 seg[0].fX1 = 1+l; seg[0].fY1 = 0+t; seg[0].fX2 = 3+l; seg[0].fY2 = 0+t;
1675 seg[1].fX1 = 0+l; seg[1].fY1 = 1+t; seg[1].fX2 = 4+l; seg[1].fY2 = 1+t;
1676 seg[2].fX1 = 0+l; seg[2].fY1 = 2+t; seg[2].fX2 = 4+l; seg[2].fY2 = 2+t;
1677 seg[3].fX1 = 0+l; seg[3].fY1 = 3+t; seg[3].fX2 = 4+l; seg[3].fY2 = 3+t;
1678 seg[4].fX1 = 1+l; seg[4].fY1 = 4+t; seg[4].fX2 = 3+l; seg[4].fY2 = 4+t;
1680 gVirtualX->DrawSegments(fId, gc, seg, 5);
1686 void TGPopupMenu::DefaultEntry(Int_t
id)
1689 TIter next(fEntryList);
1691 while ((ptr = (TGMenuEntry *) next())) {
1692 if (ptr->fEntryId ==
id)
1693 ptr->fStatus |= kMenuDefaultMask;
1695 ptr->fStatus &= ~kMenuDefaultMask;
1702 void TGPopupMenu::EnableEntry(Int_t
id)
1705 TIter next(fEntryList);
1707 while ((ptr = (TGMenuEntry *) next()))
1708 if (ptr->fEntryId ==
id) {
1709 ptr->fStatus |= kMenuEnableMask;
1710 if (ptr->fStatus & kMenuHideMask) {
1711 ptr->fStatus &= ~kMenuHideMask;
1721 void TGPopupMenu::DisableEntry(Int_t
id)
1724 TIter next(fEntryList);
1726 while ((ptr = (TGMenuEntry *) next()))
1727 if (ptr->fEntryId ==
id) { ptr->fStatus &= ~kMenuEnableMask;
break; }
1733 Bool_t TGPopupMenu::IsEntryEnabled(Int_t
id)
1736 TIter next(fEntryList);
1738 while ((ptr = (TGMenuEntry *) next()))
1739 if (ptr->fEntryId ==
id)
1740 return (ptr->fStatus & kMenuEnableMask) ? kTRUE : kFALSE;
1748 void TGPopupMenu::HideEntry(Int_t
id)
1751 TIter next(fEntryList);
1753 while ((ptr = (TGMenuEntry *) next()))
1754 if (ptr->fEntryId ==
id) {
1755 ptr->fStatus |= kMenuHideMask;
1756 ptr->fStatus &= ~kMenuEnableMask;
1765 Bool_t TGPopupMenu::IsEntryHidden(Int_t
id)
1768 TIter next(fEntryList);
1770 while ((ptr = (TGMenuEntry *) next()))
1771 if (ptr->fEntryId ==
id)
1772 return (ptr->fStatus & kMenuHideMask) ? kTRUE : kFALSE;
1779 void TGPopupMenu::CheckEntry(Int_t
id)
1782 TIter next(fEntryList);
1784 while ((ptr = (TGMenuEntry *) next()))
1785 if (ptr->fEntryId ==
id) { ptr->fStatus |= kMenuCheckedMask;
break; }
1792 void TGPopupMenu::CheckEntryByData(
void *user_data)
1795 TIter next(fEntryList);
1797 while ((ptr = (TGMenuEntry *) next()))
1798 if (ptr->fUserData == user_data) { ptr->fStatus |= kMenuCheckedMask;
break; }
1804 void TGPopupMenu::UnCheckEntry(Int_t
id)
1807 TIter next(fEntryList);
1809 while ((ptr = (TGMenuEntry *) next()))
1810 if (ptr->fEntryId ==
id) { ptr->fStatus &= ~kMenuCheckedMask;
break; }
1816 void TGPopupMenu::UnCheckEntries()
1819 TIter next(fEntryList);
1821 while ((ptr = (TGMenuEntry *) next())) {
1822 ptr->fStatus &= ~kMenuCheckedMask;
1830 void TGPopupMenu::UnCheckEntryByData(
void *user_data)
1833 TIter next(fEntryList);
1835 while ((ptr = (TGMenuEntry *) next()))
1836 if (ptr->fUserData == user_data) { ptr->fStatus &= ~kMenuCheckedMask;
break; }
1842 Bool_t TGPopupMenu::IsEntryChecked(Int_t
id)
1845 TIter next(fEntryList);
1847 while ((ptr = (TGMenuEntry *) next()))
1848 if (ptr->fEntryId ==
id)
1849 return (ptr->fStatus & kMenuCheckedMask) ? kTRUE : kFALSE;
1857 void TGPopupMenu::RCheckEntry(Int_t
id, Int_t IDfirst, Int_t IDlast)
1860 TIter next(fEntryList);
1862 while ((ptr = (TGMenuEntry *) next()))
1863 if (ptr->fEntryId ==
id)
1864 ptr->fStatus |= kMenuRadioMask | kMenuRadioEntryMask;
1866 if (ptr->fEntryId >= IDfirst && ptr->fEntryId <= IDlast) {
1867 ptr->fStatus &= ~kMenuRadioMask;
1868 ptr->fStatus |= kMenuRadioEntryMask;
1875 Bool_t TGPopupMenu::IsEntryRChecked(Int_t
id)
1878 TIter next(fEntryList);
1880 while ((ptr = (TGMenuEntry *) next()))
1881 if (ptr->fEntryId ==
id)
1882 return (ptr->fStatus & kMenuRadioMask) ? kTRUE : kFALSE;
1894 TGMenuEntry *TGPopupMenu::GetEntry(Int_t
id)
1897 TIter next(fEntryList);
1899 while ((ptr = (TGMenuEntry *) next()))
1900 if (ptr->fEntryId ==
id)
1915 TGMenuEntry *TGPopupMenu::GetEntry(
const char *s)
1917 return (TGMenuEntry*) fEntryList->FindObject(s);
1923 void TGPopupMenu::DeleteEntry(Int_t
id)
1926 TIter next(fEntryList);
1928 while ((ptr = (TGMenuEntry *) next()))
1929 if (ptr->fEntryId ==
id) {
1930 fEntryList->Remove(ptr);
1933 if (fCurrent == ptr)
1942 void TGPopupMenu::DeleteEntry(TGMenuEntry *entry)
1945 TIter next(fEntryList);
1947 while ((ptr = (TGMenuEntry *) next()))
1949 fEntryList->Remove(ptr);
1952 if (fCurrent == ptr)
1961 const TGGC &TGPopupMenu::GetDefaultGC()
1964 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1965 return *fgDefaultGC;
1971 const TGGC &TGPopupMenu::GetDefaultSelectedGC()
1973 if (!fgDefaultSelectedGC)
1974 fgDefaultSelectedGC = gClient->GetResourcePool()->GetSelectedGC();
1975 return *fgDefaultSelectedGC;
1981 const TGGC &TGPopupMenu::GetDefaultSelectedBackgroundGC()
1983 if (!fgDefaultSelectedBackgroundGC)
1984 fgDefaultSelectedBackgroundGC = gClient->GetResourcePool()->GetSelectedBckgndGC();
1985 return *fgDefaultSelectedBackgroundGC;
1991 FontStruct_t TGPopupMenu::GetDefaultFontStruct()
1994 fgDefaultFont = gClient->GetResourcePool()->GetMenuFont();
1995 return fgDefaultFont->GetFontStruct();
2001 FontStruct_t TGPopupMenu::GetHilightFontStruct()
2004 fgHilightFont = gClient->GetResourcePool()->GetMenuHiliteFont();
2005 return fgHilightFont->GetFontStruct();
2019 TGMenuTitle::TGMenuTitle(
const TGWindow *p, TGHotString *s, TGPopupMenu *menu,
2020 GContext_t norm, FontStruct_t font, UInt_t options)
2021 : TGFrame(p, 1, 1, options)
2026 fSelGC = GetDefaultSelectedGC()();
2030 fTextColor = GetForeground();
2034 if (s && (hotchar = s->GetHotChar()) != 0)
2035 fHkeycode = gVirtualX->KeysymToKeycode(hotchar);
2040 Int_t max_ascent, max_descent;
2042 tw = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
2043 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
2045 Resize(tw + 8, max_ascent + max_descent + 7);
2047 if (p && p->InheritsFrom(TGMenuBar::Class())) {
2048 TGMenuBar *bar = (TGMenuBar*)p;
2049 fMenu->SetMenuBar(bar);
2056 void TGMenuTitle::SetState(Bool_t state)
2064 gVirtualX->TranslateCoordinates(fId, (fMenu->GetParent())->GetId(),
2065 0, 0, ax, ay, wdummy);
2069 gVirtualX->SetWMTransientHint(fMenu->GetId(), GetId());
2071 fMenu->PlaceMenu(ax-1, ay+fHeight, kTRUE, kFALSE);
2075 fTitleId = fMenu->EndMenu(fTitleData);
2078 fOptions &= ~(kSunkenFrame | kRaisedFrame);
2079 fClient->NeedRedraw(
this);
2085 void TGMenuTitle::DoRedraw()
2087 TGFrame::DoRedraw();
2089 int x, y, max_ascent, max_descent;
2092 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
2095 gVirtualX->SetForeground(fNormGC, GetDefaultSelectedBackground());
2096 if (gClient->GetStyle() > 1) {
2097 gVirtualX->FillRectangle(fId, fNormGC, 1, 2, fWidth-3, fHeight-4);
2098 gVirtualX->DrawRectangle(fId, GetShadowGC()(), 1, 1, fWidth-3, fHeight-3);
2101 gVirtualX->FillRectangle(fId, fNormGC, 0, 0, fWidth, fHeight);
2103 gVirtualX->SetForeground(fNormGC, GetForeground());
2104 fLabel->Draw(fId, fSelGC, x, y + max_ascent);
2107 Pixel_t back = GetDefaultFrameBackground();
2108 if (fMenu && fMenu->fMenuBar && fMenu->fMenuBar->GetBackground() != back)
2109 back = fMenu->fMenuBar->GetBackground();
2110 gVirtualX->SetForeground(fNormGC, back);
2111 if (gClient->GetStyle() > 1) {
2112 gVirtualX->DrawRectangle(fId, fNormGC, 1, 1, fWidth-3, fHeight-3);
2113 gVirtualX->FillRectangle(fId, fNormGC, 1, 2, fWidth-3, fHeight-4);
2116 gVirtualX->FillRectangle(fId, fNormGC, 0, 0, fWidth, fHeight);
2118 gVirtualX->SetForeground(fNormGC, fTextColor);
2119 fLabel->Draw(fId, fNormGC, x, y + max_ascent);
2120 if (fTextColor != GetForeground())
2121 gVirtualX->SetForeground(fNormGC, GetForeground());
2128 void TGMenuTitle::DoSendMessage()
2131 if (fTitleId != -1) {
2132 SendMessage(fMenu->fMsgWindow, MK_MSG(kC_COMMAND, kCM_MENU), fTitleId,
2133 (Long_t)fTitleData);
2134 fMenu->Activated(fTitleId);
2141 FontStruct_t TGMenuTitle::GetDefaultFontStruct()
2144 fgDefaultFont = gClient->GetResourcePool()->GetMenuFont();
2145 return fgDefaultFont->GetFontStruct();
2151 const TGGC &TGMenuTitle::GetDefaultGC()
2154 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
2155 return *fgDefaultGC;
2161 const TGGC &TGMenuTitle::GetDefaultSelectedGC()
2163 if (!fgDefaultSelectedGC)
2164 fgDefaultSelectedGC = gClient->GetResourcePool()->GetSelectedGC();
2165 return *fgDefaultSelectedGC;
2171 void TGPopupMenu::SavePrimitive(std::ostream &out, Option_t *option )
2175 out <<
" TGPopupMenu *";
2176 out << GetName() <<
" = new TGPopupMenu(gClient->GetDefaultRoot()"
2177 <<
"," << GetWidth() <<
"," << GetHeight() <<
"," << GetOptionString() <<
");" << std::endl;
2179 Bool_t hasradio = kFALSE;
2180 Int_t r_first, r_last, r_active;
2181 r_active = r_first = r_last = -1;
2183 TGMenuEntry *mentry;
2184 TIter next(GetListOfEntries());
2186 while ((mentry = (TGMenuEntry *) next())) {
2188 Int_t i, lentext, hotpos;
2192 switch (mentry->GetType()) {
2194 text = mentry->GetName();
2195 lentext = mentry->fLabel->GetLength();
2196 hotpos = mentry->fLabel->GetHotPos();
2197 outext =
new char[lentext+2];
2199 while (text && lentext) {
2200 if (i == hotpos-1) {
2205 i++; text++; lentext--;
2208 if (mentry->fShortcut) {
2209 snprintf(shortcut, 80,
"\\t%s", mentry->GetShortcutText());
2212 memset(shortcut, 0, 80);
2215 out <<
" " << GetName() <<
"->AddEntry(" << quote
2216 << gSystem->ExpandPathName(gSystem->UnixPathName(outext))
2218 << quote <<
"," << mentry->GetEntryId();
2219 if (mentry->fUserData) {
2220 out <<
"," << mentry->fUserData;
2223 out <<
",gClient->GetPicture(" << quote
2224 << gSystem->ExpandPathName(gSystem->UnixPathName(mentry->fPic->GetName()))
2227 out <<
");" << std::endl;
2232 out <<
" // cascaded menu " << quote << mentry->GetName() << quote <<std::endl;
2233 mentry->fPopup->SavePrimitive(out, option);
2234 text = mentry->GetName();
2235 lentext = mentry->fLabel->GetLength();
2236 hotpos = mentry->fLabel->GetHotPos();
2237 outext =
new char[lentext+2];
2239 while (text && lentext) {
2240 if (i == hotpos-1) {
2245 i++; text++; lentext--;
2249 out <<
" " << GetName() <<
"->AddPopup(" << quote
2250 << outext << quote <<
"," << mentry->fPopup->GetName()
2251 <<
");" << std::endl;
2255 out <<
" " << GetName() <<
"->AddLabel(" << quote
2256 << mentry->GetName() << quote;
2258 out <<
",gClient->GetPicture(" << quote
2259 << mentry->fPic->GetName()
2262 out <<
");" << std::endl;
2264 case kMenuSeparator:
2265 out <<
" " << GetName() <<
"->AddSeparator();" << std::endl;
2269 if (!(mentry->GetStatus() & kMenuEnableMask)) {
2270 out<<
" " << GetName() <<
"->DisableEntry(" << mentry->GetEntryId()
2271 <<
");" << std::endl;
2273 if (mentry->GetStatus() & kMenuHideMask) {
2274 out<<
" " << GetName() <<
"->HideEntry(" << mentry->GetEntryId()
2275 <<
");" << std::endl;
2277 if (mentry->GetStatus() & kMenuCheckedMask) {
2278 out<<
" " << GetName() <<
"->CheckEntry(" << mentry->GetEntryId()
2279 <<
");" << std::endl;
2281 if (mentry->GetStatus() & kMenuDefaultMask) {
2282 out<<
" "<< GetName() <<
"->DefaultEntry(" << mentry->GetEntryId()
2283 <<
");" << std::endl;
2285 if (mentry->GetStatus() & kMenuRadioEntryMask) {
2287 r_last = mentry->GetEntryId();
2288 if (IsEntryRChecked(mentry->GetEntryId())) r_active = mentry->GetEntryId();
2291 r_first = mentry->GetEntryId();
2293 if (IsEntryRChecked(mentry->GetEntryId())) r_active = mentry->GetEntryId();
2295 }
else if (hasradio) {
2296 out <<
" " << GetName() <<
"->RCheckEntry(" << r_active <<
"," << r_first
2297 <<
"," << r_last <<
");" << std::endl;
2299 r_active = r_first = r_last = -1;
2307 void TGMenuTitle::SavePrimitive(std::ostream &out, Option_t *option )
2312 out <<
" // " << quote << fLabel->GetString() << quote <<
" menu" << std::endl;
2314 fMenu->SavePrimitive(out, option);
2316 const char *text = fLabel->GetString();
2317 Int_t lentext = fLabel->GetLength();
2318 Int_t hotpos = fLabel->GetHotPos();
2319 char *outext =
new char[lentext+2];
2322 if (i == hotpos-1) {
2327 i++; text++; lentext--;
2330 out <<
" " << fParent->GetName() <<
"->AddPopup(" << quote << outext
2331 << quote <<
"," << fMenu->GetName();
2339 void TGMenuBar::SavePrimitive(std::ostream &out, Option_t *option )
2342 out <<
" // menu bar" << std::endl;
2344 out <<
" TGMenuBar *";
2345 out << GetName() <<
" = new TGMenuBar(" << fParent->GetName()
2346 <<
"," << GetWidth() <<
"," << GetHeight() <<
"," << GetOptionString() <<
");" << std::endl;
2347 if (option && strstr(option,
"keep_names"))
2348 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
2355 while ((el = (TGFrameElement *)next())) {
2356 el->fFrame->SavePrimitive(out, option);
2357 el->fLayout->SavePrimitive(out, option);
2358 out <<
");" << std::endl;