Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGMenu.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 09/01/98
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11/**************************************************************************
12
13 This source is based on Xclass95, a Win95-looking GUI toolkit.
14 Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15
16 Xclass95 is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License as published by the Free Software Foundation; either
19 version 2 of the License, or (at your option) any later version.
20
21**************************************************************************/
22
23
24/** \class TGMenuBar
25 \ingroup guiwidgets
26
27The TGMenu.h header contains all different menu classes.
28
29The TGMenuBar class implements a menu bar widget. It is used to
30specify and provide access to common and frequently used application
31actions grouped under menu titles (TGMenuTitle class). The menu bar
32takes the highest-level of the menu system and it is a starting
33point for many interactions. It is always visible and allows using
34the keyboard equivalents. The geometry of the menu bar is
35automatically set to the parent widget, i.e. the menu bar
36automatically resizes itself so that it has the same width as its
37parent (typically TGMainFrame). A menu bar contains one or more
38popup menus and usually is placed along the top of the application
39window. Any popup menu is invisible until the user invokes it by
40using the mouse pointer or the keyboard.
41
42Popup menus implemented by TGPopupMenu class are unique in that,
43by convention, they are not placed with the other GUI components in
44the user interfaces. Instead, a popup menu usually appears either in
45a menu bar or as a context menu on the TOP of the GUI. For that
46reason it needs gClient->GetDefaultRoot() as a parent to get the
47pointer to the root (i.e. desktop) window. This way a popup menu
48will never be embedded.
49NOTE: Using gClient->GetRoot() as a parent of TGPopupMenu will not
50avoid the possibility of embedding the corresponding popup menu
51because the current window hierarchy can be changed by using
52gClient->SetRoot() method.
53
54As a context menus TGPopupMenu shows up after pressing the right
55mouse button, over a popup-enabled component. The popup menu then
56appears under the mouse pointer.
57
58Selecting a menu item will generate the event:
59kC_COMMAND, kCM_MENU, menu id, user data.
60
61*/
62
63
64#include "TGMenu.h"
65#include "TGResourcePool.h"
66#include "TTimer.h"
67#include "TMath.h"
68#include "TSystem.h"
69#include "TList.h"
70#include "KeySymbols.h"
71#include "TGButton.h"
72#include "TQConnection.h"
73#include "TParameter.h"
74#include "RConfigure.h"
75#include "TVirtualX.h"
76#include "snprintf.h"
77
78#include <iostream>
79
80const TGGC *TGPopupMenu::fgDefaultGC = nullptr;
83const TGFont *TGPopupMenu::fgDefaultFont = nullptr;
84const TGFont *TGPopupMenu::fgHilightFont = nullptr;
85
86const TGGC *TGMenuTitle::fgDefaultGC = nullptr;
88const TGFont *TGMenuTitle::fgDefaultFont = nullptr;
89
90
94
95
96////////////////////////////////////////////////////////////////////////////////
97
98class TPopupDelayTimer : public TTimer {
99private:
100 TGPopupMenu *fPopup; // popup menu
101public:
102 TPopupDelayTimer(TGPopupMenu *p, Long_t ms) : TTimer(ms, kTRUE) { fPopup = p; }
103 Bool_t Notify() override;
104};
105
106////////////////////////////////////////////////////////////////////////////////
107/// Notify when timer times out and reset the timer.
108
110{
112 Reset();
113 return kFALSE;
114}
115
116
117//////////////////////////////////////////////////////////////////////////
118// //
119// TGMenuBar member functions. //
120// //
121//////////////////////////////////////////////////////////////////////////
122
123////////////////////////////////////////////////////////////////////////////////
124/// Create a menu bar object.
125
127 : TGHorizontalFrame(p, w, h, options | kHorizontalFrame)
128{
129 fCurrent = 0;
130 fTitles = new TList;
131 fStick = kTRUE;
133 fTrash = new TList();
134
135 gVirtualX->GrabButton(fId, kButton1, kAnyModifier,
137 kNone, kNone);
138
140
141 fMenuMore = new TGPopupMenu(gClient->GetDefaultRoot());
142 fMenuMore->AddLabel("Hidden Menus");
145
147 fOutLayouts = new TList();
148 fNeededSpace = new TList();
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Delete menu bar object. Removes also the hot keys from the main frame,
153/// so hitting them will not cause the menus to popup.
154
156{
157 TGFrameElement *el;
158 TGMenuTitle *t;
159 Int_t keycode;
160
161 if (!MustCleanup()) {
162 fTrash->Delete();
163 }
164 delete fTrash;
165
167
168 if (!MustCleanup()) {
169 TIter next(fList);
170 while ((el = (TGFrameElement *) next())) {
171 t = (TGMenuTitle *) el->fFrame;
172 if ((keycode = t->GetHotKeyCode()) != 0 && main) {
173 main->RemoveBind(this, keycode, kKeyMod1Mask);
174 }
175 }
176 }
177
178 // delete TGMenuTitles
179 if (fTitles && !MustCleanup()) fTitles->Delete();
180 delete fTitles;
181
182 delete fOutLayouts;
184 delete fNeededSpace;
185 delete fMenuMore;
186 delete fMenuBarMoreLayout;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Calculates whether the >> menu must be shown or not and
191/// which menu titles are hidden.
192
194{
195 if (GetDefaultWidth() > GetWidth()) {
196 while (!(GetDefaultWidth() < GetWidth() ||
197 GetList()->GetSize() <= 1)) {
198 TGFrameElement* entry = GetLastOnLeft();
199 if (!entry) break;
200 TGMenuTitle* menuTitle = (TGMenuTitle*) entry->fFrame;
201 fNeededSpace->AddLast(new TParameter<Int_t>("", menuTitle->GetWidth() +
202 entry->fLayout->GetPadLeft() +
203 entry->fLayout->GetPadRight() ) );
204 fOutLayouts->AddLast( entry->fLayout );
205 fMenuMore->AddPopup( menuTitle->GetName(), menuTitle->GetMenu() );
206 menuTitle->GetMenu()->Connect("PoppedUp()", "TGMenuBar", this, "PopupConnection()");
207 RemovePopup( menuTitle->GetName() );
208 }
209 }
210
211 if (fNeededSpace->GetSize() > 0) {
212 Int_t neededWidth = ((TParameter<Int_t>*) fNeededSpace->Last())->GetVal();
213 Bool_t fit = kFALSE;
214 if (fNeededSpace->GetSize() > 1)
215 fit = GetDefaultWidth() + neededWidth + 5 < GetWidth();
216 else
217 fit = GetDefaultWidth() + neededWidth - 7 < GetWidth();
218 while (fit) {
221 ULong_t hints = (layout) ? layout->GetLayoutHints() : 0;
222 TGPopupMenu* beforeMenu = 0;
223 if (hints & kLHintsRight) {
224 TGFrameElement* entry = GetLastOnLeft();
225 if (entry) {
226 TGMenuTitle* beforeMenuTitle = (TGMenuTitle*) entry->fFrame;
227 beforeMenu = beforeMenuTitle->GetMenu();
228 }
229 }
230 if (menu && menu->GetPopup()) {
231 menu->GetPopup()->Disconnect("PoppedUp()", this, "PopupConnection()");
232 AddPopup( menu->GetName(), menu->GetPopup(), layout, beforeMenu );
233 }
236 fMenuMore->DeleteEntry(menu);
237
238 if (fNeededSpace->GetSize() > 0) {
239 neededWidth = ((TParameter<Int_t>*)fNeededSpace->Last())->GetVal();
240 if (fNeededSpace->GetSize() > 1)
241 fit = GetDefaultWidth() + neededWidth + 5 < GetWidth();
242 else
243 fit = GetDefaultWidth() + neededWidth - 7 < GetWidth();
244 } else
245 fit = kFALSE;
246 }
247 }
248
249 if (fNeededSpace->GetSize() > 0) {
250 if (!fWithExt) {
252 ((TGMenuTitle*)((TGFrameElement*)GetList()->First())->fFrame)->GetMenu());
253 fWithExt = kTRUE;
254 }
255 } else {
256 RemovePopup(">>");
258 }
259
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Returns the last visible menu title on the left of the '>>'
266/// in the menu bar.
267
269{
270 TIter next(GetList());
271 while (TGFrameElement *entry = (TGFrameElement*) next()) {
272
273 TGMenuTitle* menuTitle = (TGMenuTitle*) entry->fFrame;
274 TGLayoutHints* tmpLayout = (TGLayoutHints*) entry->fLayout;
275 ULong_t hints = tmpLayout->GetLayoutHints();
276
277 if (hints & kLHintsRight && menuTitle->GetMenu() != fMenuMore) {
278 return entry;
279 }
280 }
281
282 return ((TGFrameElement*)GetList()->Last());
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Connects the corresponding cascaded menu to the proper slots,
287/// according to the highlighted menu entry in '>>' menu.
288
290{
291 // Disconnect all previous signals
292 TList* slots = fMenuMore->GetListOfSignals();
293 TIter next (slots);
294 while (TList* connlist = (TList*) next()) {
295
296 const char* signal_name = connlist->GetName();
297 TIter next2(connlist);
298 while (TQConnection* conn = (TQConnection*) next2()) {
299 const char* slot_name = conn->GetName();
300 void* receiver = conn->GetReceiver();
301 fMenuMore->Disconnect(signal_name, receiver, slot_name);
302 }
303 }
305
306 // Check whether the current entry is a menu or not (just in case)
307 TGMenuEntry* currentEntry = fMenuMore->GetCurrent();
308 if (currentEntry->GetType() != kMenuPopup) return;
309
310 // Connect the corresponding active signals to the >> menu
311 TGPopupMenu* currentMenu = currentEntry->GetPopup();
312
313 slots = currentMenu->GetListOfSignals();
314 TIter next3 (slots);
315 while (TList* connlist = (TList*) next3()) {
316
317 const char* signal_name = connlist->GetName();
318 if (strcmp(signal_name, "Activated(int)") == 0) {
319 TIter next2(connlist);
320 while (TQConnection* conn = (TQConnection*) next2()) {
321
322 const char* slot_name = conn->GetName();
323 const char* class_name = conn->GetClassName();
324 void* receiver = conn->GetReceiver();
325 fMenuMore->Connect(signal_name, class_name, receiver, slot_name);
326 }
327 }
328 }
329
330 fMenuMore->fMsgWindow = currentMenu->fMsgWindow;
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// If on kTRUE bind arrow, popup menu hot keys, otherwise
335/// remove key bindings.
336
338{
339 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Left), kAnyModifier, on);
340 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Right), kAnyModifier, on);
341 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Up), kAnyModifier, on);
342 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Down), kAnyModifier, on);
343 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Enter), kAnyModifier, on);
344 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Return), kAnyModifier, on);
345 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_Escape), kAnyModifier, on);
346
347 if (fCurrent && fCurrent->GetMenu()) {
349 }
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// If on kTRUE bind subMenu hot keys, otherwise remove key bindings.
354
356{
357 TGMenuEntry *e;
358 TIter next(subMenu->GetListOfEntries());
359
360 while ((e = (TGMenuEntry*)next())) {
361 Int_t hot = 0;
362 if ( e->GetType() == kMenuPopup )
363 BindMenu(e->GetPopup(), on);
364 if (e->GetLabel()) {
365 hot = e->GetLabel()->GetHotChar();
366 }
367 if (!hot) continue;
368 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), 0, on);
369 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask, on);
370 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask, on);
371 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyMod2Mask, on);
372 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask, on);
373 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyMod2Mask, on);
374 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyLockMask | kKeyMod2Mask, on);
375 gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(hot), kKeyShiftMask | kKeyLockMask | kKeyMod2Mask, on);
376 }
377}
378
379
380////////////////////////////////////////////////////////////////////////////////
381/// If on kTRUE bind hot keys, otherwise remove key binding.
382
384{
386
387 if (!main || !main->InheritsFrom("TGMainFrame")) return;
388
389 if (on) {
390 // case insensitive bindings
391 main->BindKey(this, keycode, kKeyMod1Mask);
392 main->BindKey(this, keycode, kKeyMod1Mask | kKeyShiftMask);
393 main->BindKey(this, keycode, kKeyMod1Mask | kKeyLockMask);
394 main->BindKey(this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
395
396 main->BindKey(this, keycode, kKeyMod1Mask | kKeyMod2Mask);
397 main->BindKey(this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
398 main->BindKey(this, keycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
399 main->BindKey(this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
400 } else {
401 main->RemoveBind(this, keycode, kKeyMod1Mask);
402 main->RemoveBind(this, keycode, kKeyMod1Mask | kKeyShiftMask);
403 main->RemoveBind(this, keycode, kKeyMod1Mask | kKeyLockMask);
404 main->RemoveBind(this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
405
406 main->RemoveBind(this, keycode, kKeyMod1Mask | kKeyMod2Mask);
407 main->RemoveBind(this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
408 main->RemoveBind(this, keycode, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
409 main->RemoveBind(this, keycode, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
410 }
411}
412
413////////////////////////////////////////////////////////////////////////////////
414/// Add popup menu to menu bar. The hot string will be adopted by the
415/// menubar (actually the menu title) and deleted when possible.
416/// If before is not 0 the menu will be added before it.
417
419 TGPopupMenu *before)
420{
421 TGMenuTitle *t;
422 Int_t keycode;
423
424 AddFrameBefore(t = new TGMenuTitle(this, s, menu), l, before);
425 fTitles->Add(t); // keep track of menu titles for later cleanup in dtor
426
427 if ((keycode = t->GetHotKeyCode()) != 0) {
428 BindHotKey(keycode, kTRUE);
429 }
430}
431
432////////////////////////////////////////////////////////////////////////////////
433/// Add popup via created before menu title.
434
436{
437 Int_t keycode;
438
439 AddFrameBefore(title, l, before);
440 fTitles->Add(title); // keep track of menu titles for later cleanup in dtor
441
442 if ((keycode = title->GetHotKeyCode()) != 0) {
443 BindHotKey(keycode, kTRUE);
444 }
445}
446
447////////////////////////////////////////////////////////////////////////////////
448/// Add popup menu to menu bar. If before is not 0 the menu will be
449/// added before it.
450
451void TGMenuBar::AddPopup(const char *s, TGPopupMenu *menu, TGLayoutHints *l,
452 TGPopupMenu *before)
453{
454 AddPopup(new TGHotString(s), menu, l, before);
455}
456
457////////////////////////////////////////////////////////////////////////////////
458/// Add popup menu to menu bar.
459///
460/// Comment:
461/// This method is valid only for horizontal menu bars.
462/// The most common case is menu bar containing equidistant titles padding left side.
463/// TGMenuBar *bar;
464/// bar->AddPopup("title1", 10);
465/// bar->AddPopup("title2", 10);
466/// ...
467///
468/// To add equidistant titles padding right side padleft must be 0.
469/// TGMenuBar *bar;
470/// bar->AddPopup("title1", 0, 10);
471/// bar->AddPopup("title2", 0, 10);
472/// ...
473///
474/// This method guarantee automatic cleanup when menu bar is destroyed.
475/// Do not delete returned popup-menu
476
477TGPopupMenu *TGMenuBar::AddPopup(const TString &s, Int_t padleft, Int_t padright,
478 Int_t padtop, Int_t padbottom)
479{
480 ULong_t hints = kLHintsTop;
481
482 if (padleft) {
483 hints |= kLHintsLeft;
484 } else {
485 hints |= kLHintsRight;
486 }
487
488 TGLayoutHints *l = new TGLayoutHints(hints, padleft, padright,
489 padtop, padbottom);
490 fTrash->Add(l);
491
493 AddPopup(new TGHotString(s), menu, l, 0);
494 fTrash->Add(menu);
495 return menu;
496}
497
498////////////////////////////////////////////////////////////////////////////////
499/// Private version of AddFrame for menubar, to make sure that we
500/// indeed only add TGMenuTitle objects to it. If before is not 0
501/// the menu will be added before it.
502
504 TGPopupMenu *before)
505{
506 if (!f->InheritsFrom("TGMenuTitle")) {
507 Error("AddFrameBefore", "may only add TGMenuTitle objects to a menu bar");
508 return;
509 }
510
511 if (!before) {
512 AddFrame(f, l);
513 return;
514 }
515
516 TGFrameElement *nw;
517
518 nw = new TGFrameElement;
519 nw->fFrame = f;
520 nw->fLayout = l ? l : fgDefaultHints;
521 nw->fState = 1;
522
523 TGFrameElement *el;
524 TIter next(fList);
525 while ((el = (TGFrameElement *) next())) {
526 TGMenuTitle *t = (TGMenuTitle *) el->fFrame;
527 if (t->GetMenu() == before) {
528 fList->AddBefore(el, nw);
529 return;
530 }
531 }
532 fList->Add(nw);
533}
534
535////////////////////////////////////////////////////////////////////////////////
536/// Return popup menu with the specified name. Returns 0 if menu is
537/// not found. Returnes menu can be used as "before" in AddPopup().
538/// Don't use hot key (&) in name.
539
541{
542 if (!GetList()) return 0;
543
544 TGFrameElement *el;
545 TIter next(GetList());
546 TString str = s;
547
548 while ((el = (TGFrameElement *) next())) {
549 TGMenuTitle *t = (TGMenuTitle *) el->fFrame;
550 if (str == t->GetName())
551 return t->GetMenu();
552 }
553 return 0;
554}
555
556////////////////////////////////////////////////////////////////////////////////
557/// Remove popup menu from menu bar. Returned menu has to be deleted by
558/// the user, or can be re-used in another AddPopup(). Returns 0 if
559/// menu is not found. Don't use hot key (&) in name.
560
562{
563 if (!GetList()) return 0;
564
565 TGFrameElement *el;
566 TIter next(GetList());
567 TString str = s;
568
569 while ((el = (TGFrameElement *) next())) {
570 TGMenuTitle *t = (TGMenuTitle *) el->fFrame;
571 if (str == t->GetName()) {
572 Int_t keycode;
573 if ((keycode = t->GetHotKeyCode())) {
574 BindHotKey(keycode, kFALSE); // remove bind
575 }
576 TGPopupMenu *m = t->GetMenu();
577 fTitles->Remove(t);
578 t->DestroyWindow();
579 RemoveFrame(t);
580 delete t;
581 return m;
582 }
583 }
584 return 0;
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// Handle a mouse motion event in a menu bar.
589
591{
592 if (fKeyNavigate) return kTRUE;
593
594 Int_t dummy;
595 Window_t wtarget;
596 TGMenuTitle *target = 0;
597
598 if (!(event->fState & kButton1Mask))
599 fStick = kFALSE; // use some threshold!
600
601 gVirtualX->TranslateCoordinates(fId, fId, event->fX, event->fY,
602 dummy, dummy, wtarget);
603 if (wtarget) target = (TGMenuTitle*) fClient->GetWindowById(wtarget);
604
605 if (fCurrent && target && (target != fCurrent)) {
606 // deactivate all others
607 TGFrameElement *el;
608 TIter next(fList);
609 while ((el = (TGFrameElement *) next()))
610 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
611
612 fStick = kTRUE;
614 target->SetState(kTRUE);
615 }
616
617 return kTRUE;
618}
619
620////////////////////////////////////////////////////////////////////////////////
621/// Handle a mouse button event in a menubar.
622
624{
625 Int_t dummy;
626 Window_t wtarget;
628
629 // We don't need to check the button number as GrabButton will
630 // only allow button1 events
631
632 if (event->fType == kButtonPress) {
633
634 gVirtualX->TranslateCoordinates(fId, fId, event->fX, event->fY,
635 dummy, dummy, wtarget);
637
638 if (target != 0) {
639 fStick = kTRUE;
640
641 if (target != fCurrent) {
642 // deactivate all others
643 TGFrameElement *el;
644 TIter next(fList);
645 while ((el = (TGFrameElement *) next()))
646 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
647
648 fStick = kTRUE;
650 target->SetState(kTRUE);
651
654 }
655 }
656 }
657
658 if (event->fType == kButtonRelease) {
659 if (fStick) {
660 fStick = kFALSE;
661 return kTRUE;
662 }
663
664 TGFrameElement *el;
665 TIter next(fList);
666 while ((el = (TGFrameElement *) next()))
667 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
668
669 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
670
671 if (fCurrent != 0) {
672 target = fCurrent; // tricky, because WaitFor
673 fCurrent = 0;
674 if (!fKeyNavigate)
675 target->DoSendMessage();
676 }
678 }
679
680 return kTRUE;
681}
682
683////////////////////////////////////////////////////////////////////////////////
684/// Handle keyboard events in a menu bar.
685
687{
688 TGMenuTitle *target = 0;
689 TGFrameElement *el;
690 void *dummy;
691 Int_t ax, ay;
692 Window_t wdummy;
693 TIter next(fList);
694
695 if (event->fType == kGKeyPress) {
696 UInt_t keysym;
697 char tmp[2];
698
699 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
700
701 if (event->fState & kKeyMod1Mask) {
702 while ((el = (TGFrameElement *) next())) {
703 target = (TGMenuTitle *) el->fFrame;
704 if ((Int_t)event->fCode == target->GetHotKeyCode()) {
705 RequestFocus();
707 break;
708 }
709 }
710 if (el == 0) target = 0;
711 } else {
713
714 if (fCurrent) {
715 TGFrameElement *cur = 0;
716 TGPopupMenu *menu = 0;
717 next.Reset();
718 el = 0;
719 while ((el = (TGFrameElement *) next())) {
720 if (el->fFrame == fCurrent) {
721 cur = el;
722 menu = ((TGMenuTitle*)el->fFrame)->GetMenu();
723 break;
724 }
725 }
726
727 if (!menu || !menu->fPoppedUp) return kFALSE;
728
729 TGMenuEntry *ce = 0;
730
731 TGPopupMenu* currentMenu = fCurrent->GetMenu();
732 TGMenuEntry* currentEntry = currentMenu->GetCurrent();
733 while ( currentEntry ) {
734 if ( currentEntry->GetType() == kMenuPopup )
735 currentMenu = currentEntry->GetPopup();
736 if ( currentEntry != currentMenu->GetCurrent() )
737 currentEntry = currentMenu->GetCurrent();
738 else
739 currentEntry = 0;
740 }
741
742 TIter next2(currentMenu->GetListOfEntries());
743
744 while ((ce = (TGMenuEntry*)next2())) {
745 UInt_t hot = 0;
746 if (ce->GetLabel()) hot = ce->GetLabel()->GetHotChar();
747 if (!hot || (hot != keysym)) continue;
748
749 currentMenu->Activate(ce);
750 if (ce->GetType() != kMenuPopup) {
751 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
753 currentMenu->fStick = kFALSE;
754 Event_t ev;
756 ev.fWindow = currentMenu->GetId();
757 fCurrent = 0;
758 return currentMenu->HandleButton(&ev);
759 }
760 else {
761 gVirtualX->TranslateCoordinates(currentMenu->fId,
762 (ce->fPopup->GetParent())->GetId(),
763 ce->fEx+currentMenu->fMenuWidth, ce->fEy,
764 ax, ay, wdummy);
765#ifdef R__HAS_COCOA
766 gVirtualX->SetWMTransientHint(ce->fPopup->GetId(), GetId());
767#endif
768 ce->fPopup->PlaceMenu(ax-5, ay-1, kFALSE, kFALSE);
769 }
770 }
771
772 ce = menu->GetCurrent();
773 TGPopupMenu *submenu = 0;
774
775 while (ce && (ce->GetType() == kMenuPopup)) {
776 submenu = ce->GetPopup();
777 if (!submenu->fPoppedUp) break;
778 ce = submenu->GetCurrent();
779 menu = submenu;
780 }
781 switch ((EKeySym)keysym) {
782 case kKey_Left:
783 if ((submenu) && (submenu->fPoppedUp)) {
784 submenu->EndMenu(dummy);
785 break;
786 }
787 el = (TGFrameElement*)fList->Before(cur);
788 if (!el) el = (TGFrameElement*)fList->Last();
789 break;
790 case kKey_Right:
791 if (submenu) {
792 if (submenu->fPoppedUp) {
793 if (!submenu->GetCurrent()) {
794 ce = (TGMenuEntry*)submenu->GetListOfEntries()->First();
795 } else {
796 submenu->EndMenu(dummy);
797 }
798 }
799 else {
800 gVirtualX->TranslateCoordinates(menu->fId,
801 (submenu->GetParent())->GetId(),
802 ce->fEx+menu->fMenuWidth, ce->fEy,
803 ax, ay, wdummy);
804#ifdef R__HAS_COCOA
805 gVirtualX->SetWMTransientHint(submenu->GetId(), GetId());
806#endif
807 submenu->PlaceMenu(ax-5, ay-1, kFALSE, kFALSE);
808 }
809 break;
810 }
811 el = (TGFrameElement*)fList->After(cur);
812 if (!el) el = (TGFrameElement*)fList->First();
813 break;
814 case kKey_Up:
815 if (ce) ce = (TGMenuEntry*)menu->GetListOfEntries()->Before(ce);
816 while (ce && ((ce->GetType() == kMenuSeparator) ||
817 (ce->GetType() == kMenuLabel) ||
818 !(ce->GetStatus() & kMenuEnableMask))) {
819 ce = (TGMenuEntry*)menu->GetListOfEntries()->Before(ce);
820 }
821 if (!ce) ce = (TGMenuEntry*)menu->GetListOfEntries()->Last();
822 break;
823 case kKey_Down:
824 if (ce) ce = (TGMenuEntry*)menu->GetListOfEntries()->After(ce);
825 while (ce && ((ce->GetType() == kMenuSeparator) ||
826 (ce->GetType() == kMenuLabel) ||
827 !(ce->GetStatus() & kMenuEnableMask))) {
828 ce = (TGMenuEntry*)menu->GetListOfEntries()->After(ce);
829 }
830 if (!ce) ce = (TGMenuEntry*)menu->GetListOfEntries()->First();
831 break;
832 case kKey_Enter:
833 case kKey_Return: {
834 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
836 menu->fStick = kFALSE;
837 Event_t ev;
839 ev.fWindow = menu->GetId();
840 fCurrent = 0;
841 return menu->HandleButton(&ev);
842 }
843 case kKey_Escape:
844 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
846 fStick = kFALSE;
847 fCurrent = 0;
848 return menu->EndMenu(dummy);
849 default:
850 break;
851 }
852 if (ce) menu->Activate(ce);
853
854 el = el ? el : cur;
855 if (el) target = (TGMenuTitle*)el->fFrame;
856 } else {
857 return kFALSE;
858 }
859 }
860
861 if (target != 0) {
862 fStick = kTRUE;
863
864 if (target != fCurrent) {
865 // deactivate all others
866 next.Reset();
867 while ((el = (TGFrameElement *) next()))
868 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
869
871 target->SetState(kTRUE);
872 fStick = kTRUE;
873
876
877 TGMenuEntry *ptr;
878 TIter nexte(target->GetMenu()->GetListOfEntries());
879
880 while ((ptr = (TGMenuEntry *) nexte())) {
881 if ((ptr->GetStatus() & kMenuEnableMask) &&
882 !(ptr->GetStatus() & kMenuHideMask) &&
883 (ptr->GetType() != kMenuSeparator) &&
884 (ptr->GetType() != kMenuLabel)) break;
885 }
886 if (ptr)
887 target->GetMenu()->Activate(ptr);
888
889 return kTRUE;
890 }
891 } else {
892 return kFALSE;
893 }
894 }
895
896 if (event->fType == kKeyRelease) {
897 if (fStick) {
898 fStick = kFALSE;
899 return kTRUE;
900 }
901 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
902
903 next.Reset();
904 while ((el = (TGFrameElement *) next()))
905 ((TGMenuTitle*)el->fFrame)->SetState(kFALSE);
906
907 if (fCurrent != 0) {
908 target = fCurrent; // tricky, because WaitFor
909 fCurrent = 0;
910 target->DoSendMessage();
911 }
912 }
913
914 return kTRUE;
915}
916
917
918//////////////////////////////////////////////////////////////////////////
919// //
920// TGPopupMenu member functions. //
921// //
922//////////////////////////////////////////////////////////////////////////
923
924////////////////////////////////////////////////////////////////////////////////
925/// Create a popup menu.
926
928 : TGFrame(p, w, h, options | kOwnBackground)
929{
930 fNormGC = GetDefaultGC()();
936
937 // We need to change the default context to actually use the
938 // Menu Fonts. [Are we actually changing the global settings?]
939 GCValues_t gcval;
940 gcval.fMask = kGCFont;
941 gcval.fFont = gVirtualX->GetFontHandle(fFontStruct);
942 gVirtualX->ChangeGC(fNormGC, &gcval);
943 gVirtualX->ChangeGC(fSelGC, &gcval);
944
945 fDelay = 0;
946 fEntryList = new TList;
947
948 // in case any of these magic values is changes, check also Reposition()
949 fBorderWidth = 3;
950 fMenuHeight = 6;
951 fMenuWidth = 8;
952 fXl = 16;
953 fMsgWindow = p;
954 fStick = kTRUE;
955 fCurrent = 0;
958 fMenuBar = 0;
959 fSplitButton = 0;
960 fEntrySep = 3;
961
964 wattr.fOverrideRedirect = kTRUE;
965 wattr.fSaveUnder = kTRUE;
966
967 gVirtualX->ChangeWindowAttributes(fId, &wattr);
968
970}
971
972////////////////////////////////////////////////////////////////////////////////
973/// Delete a popup menu.
974
976{
977 gClient->UnregisterPopup(this);
978
980 delete fEntryList;
981 delete fDelay;
982}
983
984////////////////////////////////////////////////////////////////////////////////
985/// Add a menu entry. The hotstring is adopted by the menu (actually by
986/// the TGMenuEntry) and deleted when possible. A possible picture is
987/// borrowed from the picture pool and therefore not adopted.
988/// If before is not 0, the entry will be added before it.
989
991 const TGPicture *p, TGMenuEntry *before)
992{
993 if (!s) return;
994 TGMenuEntry *nw = new TGMenuEntry;
995 Ssiz_t tab = s->Index('\t');
996 if (tab > 0) {
997 TString ts(s->Data());
998 TString shortcut = ts(tab+1, s->Length());
999 nw->fShortcut = new TGString(shortcut.Data());
1000 nw->fLabel = new TGHotString(*s);
1001 nw->fLabel->Remove(tab);
1002 }
1003 else {
1004 nw->fLabel = s;
1005 }
1006 nw->fPic = p;
1007 nw->fType = kMenuEntry;
1008 nw->fEntryId = id;
1009 nw->fUserData = ud;
1010 nw->fPopup = 0;
1012 nw->fEx = 2;
1013 nw->fEy = fMenuHeight-2;
1014
1015 if (before)
1016 fEntryList->AddBefore(before, nw);
1017 else
1018 fEntryList->Add(nw);
1019
1020 UInt_t tw, ph = 0, pw = 0;
1021 tw = gVirtualX->TextWidth(fHifontStruct, s->GetString(), s->GetLength());
1022 if (p) {
1023 ph = p->GetHeight();
1024 pw = p->GetWidth();
1025 if (pw+12 > fXl) { fMenuWidth += pw+12-fXl; fXl = pw+12; }
1026 }
1027 if (nw->fShortcut) {
1028 tw += 10;
1029 delete s;
1030 }
1031
1032 Int_t max_ascent, max_descent;
1033 nw->fEw = tw + pw /*+8*/+18+12;
1035 gVirtualX->GetFontProperties(fHifontStruct, max_ascent, max_descent);
1036 nw->fEh = max_ascent + max_descent + fEntrySep;
1037 if (nw->fEh < ph+fEntrySep) nw->fEh = ph+fEntrySep;
1038 fMenuHeight += nw->fEh;
1039
1040 if (before)
1041 Reposition();
1042 else
1044}
1045
1046////////////////////////////////////////////////////////////////////////////////
1047/// Add a menu entry. The string s in not adopted.
1048/// If before is not 0, the entry will be added before it.
1049
1050void TGPopupMenu::AddEntry(const char *s, Int_t id, void *ud,
1051 const TGPicture *p, TGMenuEntry *before)
1052{
1053 AddEntry(new TGHotString(s), id, ud, p, before);
1054}
1055
1056////////////////////////////////////////////////////////////////////////////////
1057/// Add a menu separator to the menu.
1058/// If before is not 0, the entry will be added before it.
1059
1061{
1062 TGMenuEntry *nw = new TGMenuEntry;
1063
1064 nw->fLabel = 0;
1065 nw->fPic = 0;
1066 nw->fType = kMenuSeparator;
1067 nw->fEntryId = -1;
1068 nw->fUserData = 0;
1069 nw->fPopup = 0;
1071 nw->fEx = 2;
1072 nw->fEy = fMenuHeight-2;
1073
1074 if (before)
1075 fEntryList->AddBefore(before, nw);
1076 else
1077 fEntryList->Add(nw);
1078
1079 nw->fEw = 0;
1080 nw->fEh = 4;
1081 fMenuHeight += nw->fEh;
1082
1083 if (before)
1084 Reposition();
1085 else
1087}
1088
1089////////////////////////////////////////////////////////////////////////////////
1090/// Add a menu label to the menu. The hotstring is adopted by the menu
1091/// (actually by the TGMenuEntry) and deleted when possible. A possible
1092/// picture is borrowed from the picture pool and therefore not adopted.
1093/// If before is not 0, the entry will be added before it.
1094
1096 TGMenuEntry *before)
1097{
1098 TGMenuEntry *nw = new TGMenuEntry;
1099
1100 nw->fLabel = s;
1101 nw->fPic = p;
1102 nw->fType = kMenuLabel;
1103 nw->fEntryId = -1;
1104 nw->fUserData = 0;
1105 nw->fPopup = 0;
1107 nw->fEx = 2;
1108 nw->fEy = fMenuHeight-2;
1109
1110 if (before)
1111 fEntryList->AddBefore(before, nw);
1112 else
1113 fEntryList->Add(nw);
1114
1115 UInt_t tw, ph = 0, pw = 0;
1116 tw = gVirtualX->TextWidth(fHifontStruct, s->GetString(), s->GetLength());
1117 if (p) {
1118 ph = p->GetHeight();
1119 pw = p->GetWidth();
1120 if (pw+12 > fXl) { fMenuWidth += pw+12-fXl; fXl = pw+12; }
1121 }
1122
1123 Int_t max_ascent, max_descent;
1124 nw->fEw = tw + pw /*+8*/+18+12;
1126 gVirtualX->GetFontProperties(fHifontStruct, max_ascent, max_descent);
1127 nw->fEh = max_ascent + max_descent + fEntrySep;
1128 if (nw->fEh < ph+fEntrySep) nw->fEh = ph+fEntrySep;
1129 fMenuHeight += nw->fEh;
1130
1131 if (before)
1132 Reposition();
1133 else
1135}
1136
1137////////////////////////////////////////////////////////////////////////////////
1138/// Add a menu label to the menu. The string s in not adopted.
1139/// If before is not 0, the entry will be added before it.
1140
1141void TGPopupMenu::AddLabel(const char *s, const TGPicture *p,
1142 TGMenuEntry *before)
1143{
1144 AddLabel(new TGHotString(s), p, before);
1145}
1146
1147////////////////////////////////////////////////////////////////////////////////
1148/// Add a (cascading) popup menu to a popup menu. The hotstring is adopted
1149/// by the menu (actually by the TGMenuEntry) and deleted when possible.
1150/// If before is not 0, the entry will be added before it.
1151
1153 TGMenuEntry *before, const TGPicture *p)
1154{
1155 TGMenuEntry *nw = new TGMenuEntry;
1156
1157 nw->fLabel = s;
1158 nw->fPic = p;
1159 nw->fType = kMenuPopup;
1160 nw->fEntryId = -2;
1161 nw->fUserData = 0;
1162 nw->fPopup = popup;
1164 nw->fEx = 2;
1165 nw->fEy = fMenuHeight-2;
1166
1167 if (before)
1168 fEntryList->AddBefore(before, nw);
1169 else
1170 fEntryList->Add(nw);
1171
1172 UInt_t tw = gVirtualX->TextWidth(fHifontStruct, s->GetString(),
1173 s->GetLength());
1174
1175 UInt_t ph = 0, pw = 8;
1176 if (p) {
1177 ph = p->GetHeight();
1178 pw = p->GetWidth();
1179 if (pw+12 > fXl) { fMenuWidth += pw+12-fXl; fXl = pw+12; }
1180 }
1181 Int_t max_ascent, max_descent;
1182 nw->fEw = tw + pw+18+12;
1184 gVirtualX->GetFontProperties(fHifontStruct, max_ascent, max_descent);
1185 nw->fEh = max_ascent + max_descent + fEntrySep;
1186 if (nw->fEh < ph+fEntrySep) nw->fEh = ph+fEntrySep;
1187 fMenuHeight += nw->fEh;
1188
1189 if (before)
1190 Reposition();
1191 else
1193}
1194
1195////////////////////////////////////////////////////////////////////////////////
1196/// Add a (cascading) popup menu to a popup menu. The string s is not
1197/// adopted. If before is not 0, the entry will be added before it.
1198
1199void TGPopupMenu::AddPopup(const char *s, TGPopupMenu *popup,
1200 TGMenuEntry *before, const TGPicture *p)
1201{
1202 AddPopup(new TGHotString(s), popup, before, p);
1203}
1204
1205////////////////////////////////////////////////////////////////////////////////
1206/// Reposition entries in popup menu. Called after menu item has been
1207/// hidden or removed or inserted at a specified location.
1208
1210{
1211 // in case any of these magic values is changes, check also the ctor.
1212 fMenuHeight = 6;
1213 fMenuWidth = 8;
1214 fXl = 16;
1215
1216 TGMenuEntry *ptr;
1217 TIter next(fEntryList);
1218
1219 while ((ptr = (TGMenuEntry *) next())) {
1220
1221 if (ptr->fStatus & kMenuHideMask) continue;
1222
1223 if (ptr->fPic) {
1224 UInt_t pw = ptr->fPic->GetWidth();
1225 if (pw+12 > fXl) { fMenuWidth += pw+12-fXl; fXl = pw+12; }
1226 }
1227 ptr->fEx = 2;
1228 ptr->fEy = fMenuHeight-2;
1230 fMenuHeight += ptr->fEh;
1231 }
1233}
1234
1235////////////////////////////////////////////////////////////////////////////////
1236/// Popup a popup menu. If stick mode is true keep the menu up. If
1237/// grab_pointer is true the pointer will be grabbed, which means that
1238/// all pointer events will go to the popup menu, independent of in
1239/// which window the pointer is.
1240
1241void TGPopupMenu::PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
1242{
1243 void *ud;
1244 EndMenu(ud);
1245
1246 Int_t rx, ry;
1247 UInt_t rw, rh;
1248
1249 fStick = stick_mode;
1250 fCurrent = 0;
1251
1252 // Parent is root window for a popup menu
1253 gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);
1254
1255 if (gVirtualX->InheritsFrom("TGWin32")) {
1256 if ((x > 0) && ((x + abs(rx) + (Int_t)fMenuWidth) > (Int_t)rw))
1257 x = rw - abs(rx) - fMenuWidth;
1258 if ((y > 0) && (y + abs(ry) + (Int_t)fMenuHeight > (Int_t)rh))
1259 y = rh - fMenuHeight;
1260 } else {
1261 if (x < 0) x = 0;
1262 if (x + fMenuWidth > rw) x = rw - fMenuWidth;
1263 if (y < 0) y = 0;
1264 if (y + fMenuHeight > rh) y = rh - fMenuHeight;
1265 }
1266
1267 Move(x, y);
1268 MapRaised();
1269
1270 if (grab_pointer) {
1273 fHasGrab = kTRUE;
1274 } else {
1275 fHasGrab = kFALSE;
1276 }
1277
1278 fPoppedUp = kTRUE;
1279 PoppedUp();
1281
1282 fClient->RegisterPopup(this);
1283}
1284
1285////////////////////////////////////////////////////////////////////////////////
1286/// Close menu and return ID of selected menu item.
1287/// In case of cascading menus, recursively close all menus.
1288
1290{
1291 Int_t id;
1292
1293 if (fDelay) fDelay->Remove();
1294
1295 // destroy any cascaded children and get any ID
1296
1297 if (fCurrent != 0) {
1298
1299 // deactivate the entry
1300 fCurrent->fStatus &= ~kMenuActiveMask;
1301
1302 if ((fCurrent->fType == kMenuPopup) && fCurrent->fPopup) {
1303 id = fCurrent->fPopup->EndMenu(userData);
1304 } else {
1305 // return the ID if the entry is enabled, otherwise -1
1307 id = fCurrent->fEntryId;
1308 userData = fCurrent->fUserData;
1309 } else {
1310 id = -1;
1311 userData = 0;
1312 }
1313 }
1314
1315 } else {
1316 // if no entry selected...
1317 id = -1;
1318 userData = 0;
1319 }
1320
1321 // then unmap itself
1322 UnmapWindow();
1323
1324 gClient->UnregisterPopup(this);
1326
1327 if (fPoppedUp) {
1328 fPoppedUp = kFALSE;
1329 PoppedDown();
1330 }
1331
1332 return id;
1333}
1334
1335////////////////////////////////////////////////////////////////////////////////
1336/// Handle button event in the popup menu.
1337
1339{
1340 int id;
1341 void *ud = 0;
1342
1343 if (event->fType == kButtonRelease) {
1344 if (fStick) {
1345 fStick = kFALSE;
1346 return kTRUE;
1347 }
1348 //if (fCurrent != 0)
1349 // if (fCurrent->fType == kMenuPopup) return kTRUE;
1350 id = EndMenu(ud);
1351 if (fHasGrab) gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab
1352 if (fCurrent != 0) {
1353 fCurrent->fStatus &= ~kMenuActiveMask;
1356 (Longptr_t)ud);
1357 Activated(id);
1358 }
1359 }
1360 }
1361 return kTRUE;
1362}
1363
1364////////////////////////////////////////////////////////////////////////////////
1365/// Handle pointer crossing event in popup menu.
1366
1368{
1369 if (event->fType == kEnterNotify) {
1370
1371 TGMenuEntry *ptr;
1372 TIter next(fEntryList);
1373
1374 while ((ptr = (TGMenuEntry *) next())) {
1375 if (ptr->fStatus & kMenuHideMask) continue;
1376
1377 if ((event->fX >= ptr->fEx) && (event->fX <= ptr->fEx+(Int_t)fMenuWidth-10) &&
1378 (event->fY >= ptr->fEy) && (event->fY <= ptr->fEy+(Int_t)ptr->fEh))
1379 break;
1380 }
1381 Activate(ptr);
1382 } else {
1383 Activate((TGMenuEntry*)0);
1384 }
1387
1388 return kTRUE;
1389}
1390
1391////////////////////////////////////////////////////////////////////////////////
1392/// Handle pointer motion event in popup menu.
1393
1395{
1396 TGFrame::HandleMotion(event);
1397 static Int_t twice = 0;
1398 TGMenuEntry *ptr;
1399 TIter next(fEntryList);
1400
1401 if (twice < 2) {
1402 // hack to eat mouse move events generated by Windows when
1403 // pressing/releasing a mouse button
1404 ++twice;
1405 }
1406 else {
1407 twice = 0;
1408 fStick = kFALSE; // be careful with this, use some threshold
1409 }
1410 while ((ptr = (TGMenuEntry *) next())) {
1411 if (ptr->fStatus & kMenuHideMask) continue;
1412
1413 if ((event->fX >= ptr->fEx) && (event->fX <= ptr->fEx+(Int_t)fMenuWidth-4) && //fMenuWidth-10??
1414 (event->fY >= ptr->fEy) && (event->fY <= ptr->fEy+(Int_t)ptr->fEh))
1415 break;
1416 }
1417 Activate(ptr);
1418
1419 return kTRUE;
1420}
1421
1422////////////////////////////////////////////////////////////////////////////////
1423/// Activate a menu entry in a popup menu.
1424
1426{
1427 if (entry == fCurrent) return;
1428
1429 //-- Deactivate the current entry
1430
1431 if (fCurrent != 0) {
1432 void *ud;
1433 if (entry == 0 && fCurrent->fType == kMenuPopup) return;
1434 if ((fCurrent->fType == kMenuPopup) && fCurrent->fPopup)
1435 fCurrent->fPopup->EndMenu(ud);
1436 fCurrent->fStatus &= ~kMenuActiveMask;
1438 }
1439
1440 if (fDelay) fDelay->Remove();
1441
1442 //-- Activate the new one
1443
1444 if (entry) {
1445 entry->fStatus |= kMenuActiveMask;
1446 DrawEntry(entry);
1447 if (entry->fType == kMenuPopup) {
1448 if (!fDelay) fDelay = new TPopupDelayTimer(this, 350);
1449 fDelay->Reset();
1451 // after delay expires it will popup the cascading popup menu
1452 // iff it is still the current entry
1453 } else if (entry->fType == kMenuEntry) {
1454 // test...
1456 entry->fEntryId, (Longptr_t)entry->fUserData);
1457 Highlighted(entry->fEntryId);
1458 }
1459 }
1460 fCurrent = entry;
1461}
1462
1463////////////////////////////////////////////////////////////////////////////////
1464/// If TPopupDelayTimer times out popup cascading popup menu (if it is
1465/// still the current entry).
1466
1468{
1469 if (fCurrent != 0) {
1470 if ((fCurrent->fType == kMenuPopup) && fCurrent->fPopup) {
1471 Int_t ax, ay;
1472 Window_t wdummy;
1473
1474 gVirtualX->TranslateCoordinates(fId,
1475 (fCurrent->fPopup->GetParent())->GetId(),
1477 ax, ay, wdummy);
1478#ifdef R__HAS_COCOA
1479 gVirtualX->SetWMTransientHint(fCurrent->fPopup->GetId(), GetId());
1480#endif
1481 fCurrent->fPopup->PlaceMenu(ax-5, ay-1, kFALSE, kFALSE);
1482 }
1483 }
1484 fDelay->Remove();
1485
1486 return kTRUE;
1487}
1488
1489////////////////////////////////////////////////////////////////////////////////
1490/// Draw popup menu.
1491
1493{
1495
1496 TGMenuEntry *ptr;
1497 TIter next(fEntryList);
1498
1499 while ((ptr = (TGMenuEntry *) next()))
1500 DrawEntry(ptr);
1501}
1502
1503////////////////////////////////////////////////////////////////////////////////
1504/// Draw popup menu entry.
1505
1507{
1508 FontStruct_t font;
1509 GCValues_t gcval;
1510
1511 if (entry->fStatus & kMenuHideMask)
1512 return;
1513
1514 if (entry->fStatus & kMenuDefaultMask) {
1515 font = fHifontStruct;
1516 gcval.fMask = kGCFont;
1517 gcval.fFont = gVirtualX->GetFontHandle(font);
1518 gVirtualX->ChangeGC(fNormGC, &gcval);
1519 gVirtualX->ChangeGC(fSelGC, &gcval);
1520 } else {
1521 font = fFontStruct;
1522 }
1523
1524 UInt_t tw = 0;
1525 int max_ascent, max_descent;
1526 gVirtualX->GetFontProperties(font, max_ascent, max_descent);
1527 int tx = entry->fEx + fXl;
1528 // center text
1529 int offset = (entry->fEh - (max_ascent + max_descent)) / 2;
1530 int ty = entry->fEy + max_ascent + offset - 1;
1531 if (entry->fShortcut)
1532 tw = 7 + gVirtualX->TextWidth(fFontStruct, entry->fShortcut->Data(), entry->fShortcut->Length());
1533
1534 switch (entry->fType) {
1535 case kMenuPopup:
1536 case kMenuLabel:
1537 case kMenuEntry:
1538 if ((entry->fStatus & kMenuActiveMask) && entry->fType != kMenuLabel) {
1539 gVirtualX->FillRectangle(fId, fSelbackGC, entry->fEx+1, entry->fEy-1,
1540 fMenuWidth-6, entry->fEh);
1541 if (gClient->GetStyle() > 1)
1542 gVirtualX->DrawRectangle(fId, GetShadowGC()(), entry->fEx+1, entry->fEy-2,
1543 fMenuWidth-7, entry->fEh);
1544 if (entry->fType == kMenuPopup)
1545 DrawTrianglePattern(fSelGC, fMenuWidth-10, entry->fEy+fEntrySep, fMenuWidth-6, entry->fEy+11);
1546 if (entry->fStatus & kMenuCheckedMask)
1547 DrawCheckMark(fSelGC, 6, entry->fEy+fEntrySep, 14, entry->fEy+11);
1548 if (entry->fStatus & kMenuRadioMask)
1549 DrawRCheckMark(fSelGC, 6, entry->fEy+fEntrySep, 14, entry->fEy+11);
1550 if (entry->fPic != 0)
1551 entry->fPic->Draw(fId, fSelGC, 8, entry->fEy+1);
1552 entry->fLabel->Draw(fId,
1553 (entry->fStatus & kMenuEnableMask) ? fSelGC : GetShadowGC()(),
1554 tx, ty);
1555 if (entry->fShortcut)
1556 entry->fShortcut->Draw(fId, (entry->fStatus & kMenuEnableMask) ? fSelGC : GetShadowGC()(),
1557 fMenuWidth - tw, ty);
1558 } else {
1559 if (gClient->GetStyle() > 1)
1560 gVirtualX->DrawRectangle(fId, GetBckgndGC()(), entry->fEx+1, entry->fEy-2,
1561 fMenuWidth-7, entry->fEh);
1562 gVirtualX->FillRectangle(fId, GetBckgndGC()(), entry->fEx+1, entry->fEy-1,
1563 fMenuWidth-6, entry->fEh);
1564 if (entry->fType == kMenuPopup)
1566 if (entry->fStatus & kMenuCheckedMask)
1567 DrawCheckMark(fNormGC, 6, entry->fEy+fEntrySep, 14, entry->fEy+11);
1568 if (entry->fStatus & kMenuRadioMask)
1569 DrawRCheckMark(fNormGC, 6, entry->fEy+fEntrySep, 14, entry->fEy+11);
1570 if (entry->fPic != 0)
1571 entry->fPic->Draw(fId, fNormGC, 8, entry->fEy+1);
1572 if (entry->fStatus & kMenuEnableMask) {
1573 entry->fLabel->Draw(fId, fNormGC, tx, ty);
1574 if (entry->fShortcut)
1575 entry->fShortcut->Draw(fId, fNormGC, fMenuWidth - tw, ty);
1576 } else {
1577 entry->fLabel->Draw(fId, GetHilightGC()(), tx+1, ty+1);
1578 entry->fLabel->Draw(fId, GetShadowGC()(), tx, ty);
1579 if (entry->fShortcut) {
1580 entry->fShortcut->Draw(fId, GetHilightGC()(), fMenuWidth - tw+1, ty+1);
1581 entry->fShortcut->Draw(fId, GetShadowGC()(), fMenuWidth - tw, ty);
1582 }
1583 }
1584 }
1585 break;
1586
1587 case kMenuSeparator:
1588 gVirtualX->DrawLine(fId, GetShadowGC()(), 2, entry->fEy, fMenuWidth-fEntrySep, entry->fEy);
1589 gVirtualX->DrawLine(fId, GetHilightGC()(), 2, entry->fEy+1, fMenuWidth-fEntrySep, entry->fEy+1);
1590 break;
1591 }
1592
1593 // restore font
1594 if (entry->fStatus & kMenuDefaultMask) {
1595 gcval.fFont = gVirtualX->GetFontHandle(fFontStruct);
1596 gVirtualX->ChangeGC(fNormGC, &gcval);
1597 gVirtualX->ChangeGC(fSelGC, &gcval);
1598 }
1599}
1600
1601////////////////////////////////////////////////////////////////////////////////
1602/// Draw border round popup menu.
1603
1605{
1606 if (gClient->GetStyle() > 0) {
1607 // new modern (flat) version
1608 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fMenuHeight-1);
1609 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, fMenuHeight-1, fMenuWidth-1, fMenuHeight-1);
1610 gVirtualX->DrawLine(fId, GetShadowGC()(), fMenuWidth-1, fMenuHeight-1, fMenuWidth-1, 0);
1611 gVirtualX->DrawLine(fId, GetShadowGC()(), fMenuWidth-1, 0, 0, 0);
1612 }
1613 else {
1614 // old (raised frame) version
1615 gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, fMenuWidth-2, 0);
1616 gVirtualX->DrawLine(fId, GetBckgndGC()(), 0, 0, 0, fMenuHeight-2);
1617 gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, fMenuWidth-fEntrySep, 1);
1618 gVirtualX->DrawLine(fId, GetHilightGC()(), 1, 1, 1, fMenuHeight-fEntrySep);
1619
1620 gVirtualX->DrawLine(fId, GetShadowGC()(), 1, fMenuHeight-2, fMenuWidth-2, fMenuHeight-2);
1621 gVirtualX->DrawLine(fId, GetShadowGC()(), fMenuWidth-2, fMenuHeight-2, fMenuWidth-2, 1);
1622 gVirtualX->DrawLine(fId, GetBlackGC()(), 0, fMenuHeight-1, fMenuWidth-1, fMenuHeight-1);
1623 gVirtualX->DrawLine(fId, GetBlackGC()(), fMenuWidth-1, fMenuHeight-1, fMenuWidth-1, 0);
1624 }
1625}
1626
1627////////////////////////////////////////////////////////////////////////////////
1628/// Draw triangle pattern. Used for menu entries that are of type
1629/// kMenuPopup (i.e. cascading menus).
1630
1632 Int_t r, Int_t b)
1633{
1634 Point_t points[3];
1635
1636 int m = (t + b) >> 1;
1637
1638 points[0].fX = l;
1639 points[0].fY = t;
1640 points[1].fX = l;
1641 points[1].fY = b;
1642 points[2].fX = r;
1643 points[2].fY = m;
1644
1645 gVirtualX->FillPolygon(fId, gc, points, 3);
1646}
1647
1648////////////////////////////////////////////////////////////////////////////////
1649/// Draw check mark. Used for checked button type menu entries.
1650
1652{
1653 Segment_t seg[6];
1654
1655 t = (t + b - 8) >> 1; ++t;
1656
1657 seg[0].fX1 = 1+l; seg[0].fY1 = 3+t; seg[0].fX2 = 3+l; seg[0].fY2 = 5+t;
1658 seg[1].fX1 = 1+l; seg[1].fY1 = 4+t; seg[1].fX2 = 3+l; seg[1].fY2 = 6+t;
1659 seg[2].fX1 = 1+l; seg[2].fY1 = 5+t; seg[2].fX2 = 3+l; seg[2].fY2 = 7+t;
1660 seg[3].fX1 = 3+l; seg[3].fY1 = 5+t; seg[3].fX2 = 7+l; seg[3].fY2 = 1+t;
1661 seg[4].fX1 = 3+l; seg[4].fY1 = 6+t; seg[4].fX2 = 7+l; seg[4].fY2 = 2+t;
1662 seg[5].fX1 = 3+l; seg[5].fY1 = 7+t; seg[5].fX2 = 7+l; seg[5].fY2 = 3+t;
1663
1664 gVirtualX->DrawSegments(fId, gc, seg, 6);
1665}
1666
1667////////////////////////////////////////////////////////////////////////////////
1668/// Draw radio check mark. Used for radio button type menu entries.
1669
1671{
1672 Segment_t seg[5];
1673
1674 t = (t + b - 5) >> 1; ++t;
1675 l = (l + r - 5) >> 1; ++l;
1676
1677 seg[0].fX1 = 1+l; seg[0].fY1 = 0+t; seg[0].fX2 = 3+l; seg[0].fY2 = 0+t;
1678 seg[1].fX1 = 0+l; seg[1].fY1 = 1+t; seg[1].fX2 = 4+l; seg[1].fY2 = 1+t;
1679 seg[2].fX1 = 0+l; seg[2].fY1 = 2+t; seg[2].fX2 = 4+l; seg[2].fY2 = 2+t;
1680 seg[3].fX1 = 0+l; seg[3].fY1 = 3+t; seg[3].fX2 = 4+l; seg[3].fY2 = 3+t;
1681 seg[4].fX1 = 1+l; seg[4].fY1 = 4+t; seg[4].fX2 = 3+l; seg[4].fY2 = 4+t;
1682
1683 gVirtualX->DrawSegments(fId, gc, seg, 5);
1684}
1685
1686////////////////////////////////////////////////////////////////////////////////
1687/// Set default entry (default entries are drawn with bold text).
1688
1690{
1691 TGMenuEntry *ptr;
1692 TIter next(fEntryList);
1693
1694 while ((ptr = (TGMenuEntry *) next())) {
1695 if (ptr->fEntryId == id)
1696 ptr->fStatus |= kMenuDefaultMask;
1697 else
1698 ptr->fStatus &= ~kMenuDefaultMask;
1699 }
1700}
1701
1702////////////////////////////////////////////////////////////////////////////////
1703/// Enable entry. By default entries are enabled.
1704
1706{
1707 TGMenuEntry *ptr;
1708 TIter next(fEntryList);
1709
1710 while ((ptr = (TGMenuEntry *) next()))
1711 if (ptr->fEntryId == id) {
1712 ptr->fStatus |= kMenuEnableMask;
1713 if (ptr->fStatus & kMenuHideMask) {
1714 ptr->fStatus &= ~kMenuHideMask;
1715 Reposition();
1716 }
1717 break;
1718 }
1719}
1720
1721////////////////////////////////////////////////////////////////////////////////
1722/// Disable entry (disabled entries appear in a sunken relieve).
1723
1725{
1726 TGMenuEntry *ptr;
1727 TIter next(fEntryList);
1728
1729 while ((ptr = (TGMenuEntry *) next()))
1730 if (ptr->fEntryId == id) { ptr->fStatus &= ~kMenuEnableMask; break; }
1731}
1732
1733////////////////////////////////////////////////////////////////////////////////
1734/// Return true if menu entry is enabled.
1735
1737{
1738 TGMenuEntry *ptr;
1739 TIter next(fEntryList);
1740
1741 while ((ptr = (TGMenuEntry *) next()))
1742 if (ptr->fEntryId == id)
1743 return (ptr->fStatus & kMenuEnableMask) ? kTRUE : kFALSE;
1744 return kFALSE;
1745}
1746
1747////////////////////////////////////////////////////////////////////////////////
1748/// Hide entry (hidden entries are not shown in the menu).
1749/// To enable a hidden entry call EnableEntry().
1750
1752{
1753 TGMenuEntry *ptr;
1754 TIter next(fEntryList);
1755
1756 while ((ptr = (TGMenuEntry *) next()))
1757 if (ptr->fEntryId == id) {
1758 ptr->fStatus |= kMenuHideMask;
1759 ptr->fStatus &= ~kMenuEnableMask;
1760 Reposition();
1761 break;
1762 }
1763}
1764
1765////////////////////////////////////////////////////////////////////////////////
1766/// Return true if menu entry is hidden.
1767
1769{
1770 TGMenuEntry *ptr;
1771 TIter next(fEntryList);
1772
1773 while ((ptr = (TGMenuEntry *) next()))
1774 if (ptr->fEntryId == id)
1775 return (ptr->fStatus & kMenuHideMask) ? kTRUE : kFALSE;
1776 return kFALSE;
1777}
1778
1779////////////////////////////////////////////////////////////////////////////////
1780/// Check a menu entry (i.e. add a check mark in front of it).
1781
1783{
1784 TGMenuEntry *ptr;
1785 TIter next(fEntryList);
1786
1787 while ((ptr = (TGMenuEntry *) next()))
1788 if (ptr->fEntryId == id) { ptr->fStatus |= kMenuCheckedMask; break; }
1789}
1790
1791////////////////////////////////////////////////////////////////////////////////
1792/// Check a menu entry (i.e. add a check mark in front of it).
1793/// The input argument is user data associated with entry
1794
1796{
1797 TGMenuEntry *ptr;
1798 TIter next(fEntryList);
1799
1800 while ((ptr = (TGMenuEntry *) next()))
1801 if (ptr->fUserData == user_data) { ptr->fStatus |= kMenuCheckedMask; break; }
1802}
1803
1804////////////////////////////////////////////////////////////////////////////////
1805/// Uncheck menu entry (i.e. remove check mark).
1806
1808{
1809 TGMenuEntry *ptr;
1810 TIter next(fEntryList);
1811
1812 while ((ptr = (TGMenuEntry *) next()))
1813 if (ptr->fEntryId == id) { ptr->fStatus &= ~kMenuCheckedMask; break; }
1814}
1815
1816////////////////////////////////////////////////////////////////////////////////
1817/// Uncheck all entries.
1818
1820{
1821 TGMenuEntry *ptr;
1822 TIter next(fEntryList);
1823
1824 while ((ptr = (TGMenuEntry *) next())) {
1825 ptr->fStatus &= ~kMenuCheckedMask;
1826 }
1827}
1828
1829////////////////////////////////////////////////////////////////////////////////
1830/// Uncheck a menu entry (i.e. remove check mark in front of it).
1831/// The input argument is user data associated with entry
1832
1834{
1835 TGMenuEntry *ptr;
1836 TIter next(fEntryList);
1837
1838 while ((ptr = (TGMenuEntry *) next()))
1839 if (ptr->fUserData == user_data) { ptr->fStatus &= ~kMenuCheckedMask; break; }
1840}
1841
1842////////////////////////////////////////////////////////////////////////////////
1843/// Return true if menu item is checked.
1844
1846{
1847 TGMenuEntry *ptr;
1848 TIter next(fEntryList);
1849
1850 while ((ptr = (TGMenuEntry *) next()))
1851 if (ptr->fEntryId == id)
1852 return (ptr->fStatus & kMenuCheckedMask) ? kTRUE : kFALSE;
1853 return kFALSE;
1854}
1855
1856////////////////////////////////////////////////////////////////////////////////
1857/// Radio-select entry (note that they cannot be unselected,
1858/// the selection must be moved to another entry instead).
1859
1861{
1862 TGMenuEntry *ptr;
1863 TIter next(fEntryList);
1864
1865 while ((ptr = (TGMenuEntry *) next()))
1866 if (ptr->fEntryId == id)
1868 else
1869 if (ptr->fEntryId >= IDfirst && ptr->fEntryId <= IDlast) {
1870 ptr->fStatus &= ~kMenuRadioMask;
1872 }
1873}
1874
1875////////////////////////////////////////////////////////////////////////////////
1876/// Return true if menu item has radio check mark.
1877
1879{
1880 TGMenuEntry *ptr;
1881 TIter next(fEntryList);
1882
1883 while ((ptr = (TGMenuEntry *) next()))
1884 if (ptr->fEntryId == id)
1885 return (ptr->fStatus & kMenuRadioMask) ? kTRUE : kFALSE;
1886 return kFALSE;
1887}
1888
1889////////////////////////////////////////////////////////////////////////////////
1890/// Find entry with specified id. Use the returned entry in DeleteEntry()
1891/// or as the "before" item in the AddXXXX() methods. Returns 0 if entry
1892/// is not found. To find entries that don't have an id like the separators,
1893/// use the GetListOfEntries() method to get the complete entry
1894/// list and iterate over it and check the type of each entry
1895/// to find the separators.
1896
1898{
1899 TGMenuEntry *ptr;
1900 TIter next(fEntryList);
1901
1902 while ((ptr = (TGMenuEntry *) next()))
1903 if (ptr->fEntryId == id)
1904 return ptr;
1905 return 0;
1906}
1907
1908////////////////////////////////////////////////////////////////////////////////
1909/// Find entry with specified name. Name must match the original
1910/// name without hot key symbol, like "Print" and not "&Print".
1911/// Use the returned entry in DeleteEntry() or as the "before" item
1912/// in the AddXXXX() methods. Returns 0 if entry is not found.
1913/// To find entries that don't have a name like the separators,
1914/// use the GetListOfEntries() method to get the complete entry
1915/// list and iterate over it and check the type of each entry
1916/// to find the separators.
1917
1919{
1920 return (TGMenuEntry*) fEntryList->FindObject(s);
1921}
1922
1923////////////////////////////////////////////////////////////////////////////////
1924/// Delete entry with specified id from menu.
1925
1927{
1928 TGMenuEntry *ptr;
1929 TIter next(fEntryList);
1930
1931 while ((ptr = (TGMenuEntry *) next()))
1932 if (ptr->fEntryId == id) {
1933 fEntryList->Remove(ptr);
1934 delete ptr;
1935 Reposition();
1936 if (fCurrent == ptr)
1937 fCurrent = 0;
1938 return;
1939 }
1940}
1941
1942////////////////////////////////////////////////////////////////////////////////
1943/// Delete specified entry from menu.
1944
1946{
1947 TGMenuEntry *ptr;
1948 TIter next(fEntryList);
1949
1950 while ((ptr = (TGMenuEntry *) next()))
1951 if (ptr == entry) {
1952 fEntryList->Remove(ptr);
1953 delete ptr;
1954 Reposition();
1955 if (fCurrent == ptr)
1956 fCurrent = 0;
1957 return;
1958 }
1959}
1960
1961////////////////////////////////////////////////////////////////////////////////
1962/// Return default graphics context.
1963
1965{
1966 if (!fgDefaultGC)
1967 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1968 return *fgDefaultGC;
1969}
1970
1971////////////////////////////////////////////////////////////////////////////////
1972/// Return the selection graphics context in use.
1973
1975{
1977 fgDefaultSelectedGC = gClient->GetResourcePool()->GetSelectedGC();
1978 return *fgDefaultSelectedGC;
1979}
1980
1981////////////////////////////////////////////////////////////////////////////////
1982/// Return the selection background graphics context in use.
1983
1985{
1987 fgDefaultSelectedBackgroundGC = gClient->GetResourcePool()->GetSelectedBckgndGC();
1989}
1990
1991////////////////////////////////////////////////////////////////////////////////
1992/// Return the default font structure in use.
1993
1995{
1996 if (!fgDefaultFont)
1997 fgDefaultFont = gClient->GetResourcePool()->GetMenuFont();
1998 return fgDefaultFont->GetFontStruct();
1999}
2000
2001////////////////////////////////////////////////////////////////////////////////
2002/// Return the font structure in use for highlighted menu entries.
2003
2005{
2006 if (!fgHilightFont)
2007 fgHilightFont = gClient->GetResourcePool()->GetMenuHiliteFont();
2008 return fgHilightFont->GetFontStruct();
2009}
2010
2011
2012//////////////////////////////////////////////////////////////////////////
2013// //
2014// TGMenuTitle member functions. //
2015// //
2016//////////////////////////////////////////////////////////////////////////
2017
2018////////////////////////////////////////////////////////////////////////////////
2019/// Create a menu title. This object is created by a menu bar when adding
2020/// a popup menu. The menu title adopts the hotstring.
2021
2023 GContext_t norm, FontStruct_t font, UInt_t options)
2024 : TGFrame(p, 1, 1, options)
2025{
2026 fLabel = s;
2027 fMenu = menu;
2028 fFontStruct = font;
2030 fNormGC = norm;
2031 fState = kFALSE;
2032 fTitleId = -1;
2034 fTitleData = 0;
2035
2036 Int_t hotchar;
2037 if (s && (hotchar = s->GetHotChar()) != 0)
2038 fHkeycode = gVirtualX->KeysymToKeycode(hotchar);
2039 else
2040 fHkeycode = 0;
2041
2042 UInt_t tw = 0;
2043 Int_t max_ascent, max_descent;
2044 if (fLabel)
2045 tw = gVirtualX->TextWidth(fFontStruct, fLabel->GetString(), fLabel->GetLength());
2046 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
2047
2048 Resize(tw + 8, max_ascent + max_descent + 7);
2049
2050 if (p && p->InheritsFrom(TGMenuBar::Class())) {
2051 TGMenuBar *bar = (TGMenuBar*)p;
2052 fMenu->SetMenuBar(bar);
2053 }
2054}
2055
2056////////////////////////////////////////////////////////////////////////////////
2057/// Set state of menu title.
2058
2060{
2061 fState = state;
2062 if (state) {
2063 if (fMenu != 0) {
2064 Int_t ax, ay;
2065 Window_t wdummy;
2066
2067 gVirtualX->TranslateCoordinates(fId, (fMenu->GetParent())->GetId(),
2068 0, 0, ax, ay, wdummy);
2069
2070 // place the menu just under the window:
2071#ifdef R__HAS_COCOA
2072 gVirtualX->SetWMTransientHint(fMenu->GetId(), GetId());
2073#endif
2074 fMenu->PlaceMenu(ax-1, ay+fHeight, kTRUE, kFALSE); //kTRUE);
2075 }
2076 } else {
2077 if (fMenu != 0) {
2079 }
2080 }
2082 fClient->NeedRedraw(this);
2083}
2084
2085////////////////////////////////////////////////////////////////////////////////
2086/// Draw a menu title.
2087
2089{
2091
2092 int x, y, max_ascent, max_descent;
2093 x = y = 4;
2094
2095 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
2096
2097 if (fState) {
2099 if (gClient->GetStyle() > 1) {
2100 gVirtualX->FillRectangle(fId, fNormGC, 1, 2, fWidth-3, fHeight-4);
2101 gVirtualX->DrawRectangle(fId, GetShadowGC()(), 1, 1, fWidth-3, fHeight-3);
2102 }
2103 else {
2104 gVirtualX->FillRectangle(fId, fNormGC, 0, 0, fWidth, fHeight);
2105 }
2106 gVirtualX->SetForeground(fNormGC, GetForeground());
2107 fLabel->Draw(fId, fSelGC, x, y + max_ascent);
2108 } else {
2109 // Use same background color than the menu bar
2111 if (fMenu && fMenu->fMenuBar && fMenu->fMenuBar->GetBackground() != back)
2112 back = fMenu->fMenuBar->GetBackground();
2113 gVirtualX->SetForeground(fNormGC, back);
2114 if (gClient->GetStyle() > 1) {
2115 gVirtualX->DrawRectangle(fId, fNormGC, 1, 1, fWidth-3, fHeight-3);
2116 gVirtualX->FillRectangle(fId, fNormGC, 1, 2, fWidth-3, fHeight-4);
2117 }
2118 else {
2119 gVirtualX->FillRectangle(fId, fNormGC, 0, 0, fWidth, fHeight);
2120 }
2121 gVirtualX->SetForeground(fNormGC, fTextColor);
2122 fLabel->Draw(fId, fNormGC, x, y + max_ascent);
2123 if (fTextColor != GetForeground())
2124 gVirtualX->SetForeground(fNormGC, GetForeground());
2125 }
2126}
2127
2128////////////////////////////////////////////////////////////////////////////////
2129/// Send final selected menu item to be processed.
2130
2132{
2133 if (fMenu)
2134 if (fTitleId != -1) {
2138 }
2139}
2140
2141////////////////////////////////////////////////////////////////////////////////
2142/// Return default font structure in use.
2143
2145{
2146 if (!fgDefaultFont)
2147 fgDefaultFont = gClient->GetResourcePool()->GetMenuFont();
2148 return fgDefaultFont->GetFontStruct();
2149}
2150
2151////////////////////////////////////////////////////////////////////////////////
2152/// Return default graphics context in use.
2153
2155{
2156 if (!fgDefaultGC)
2157 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
2158 return *fgDefaultGC;
2159}
2160
2161////////////////////////////////////////////////////////////////////////////////
2162/// Return default selection graphics context in use.
2163
2165{
2167 fgDefaultSelectedGC = gClient->GetResourcePool()->GetSelectedGC();
2168 return *fgDefaultSelectedGC;
2169}
2170
2171////////////////////////////////////////////////////////////////////////////////
2172/// Save a popup menu widget as a C++ statement(s) on output stream out.
2173
2174void TGPopupMenu::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2175{
2176 char quote = '"';
2177
2178 out << " TGPopupMenu *";
2179 out << GetName() << " = new TGPopupMenu(gClient->GetDefaultRoot()"
2180 << "," << GetWidth() << "," << GetHeight() << "," << GetOptionString() << ");" << std::endl;
2181
2182 Bool_t hasradio = kFALSE;
2183 Int_t r_first, r_last, r_active;
2184 r_active = r_first = r_last = -1;
2185
2186 TGMenuEntry *mentry;
2187 TIter next(GetListOfEntries());
2188
2189 while ((mentry = (TGMenuEntry *) next())) {
2190 const char *text;
2191 Int_t i, lentext, hotpos;
2192 char shortcut[80];
2193 char *outext;
2194
2195 switch (mentry->GetType()) {
2196 case kMenuEntry:
2197 text = mentry->GetName();
2198 lentext = mentry->fLabel->GetLength();
2199 hotpos = mentry->fLabel->GetHotPos();
2200 outext = new char[lentext+2];
2201 i=0;
2202 while (text && lentext) {
2203 if (i == hotpos-1) {
2204 outext[i] = '&';
2205 i++;
2206 }
2207 outext[i] = *text;
2208 i++; text++; lentext--;
2209 }
2210 outext[i]=0;
2211 if (mentry->fShortcut) {
2212 snprintf(shortcut, 80, "\\t%s", mentry->GetShortcutText());
2213 } else {
2214 memset(shortcut, 0, 80);
2215 }
2216
2217 {
2218 TString entrytext = gSystem->UnixPathName(outext);
2219 gSystem->ExpandPathName(entrytext);
2220 out << " " << GetName() << "->AddEntry(" << quote
2221 << entrytext // can be a file name
2222 << shortcut
2223 << quote << "," << mentry->GetEntryId();
2224 }
2225 if (mentry->fUserData) {
2226 out << "," << mentry->fUserData;
2227 }
2228 if (mentry->fPic) {
2229 TString picname = gSystem->UnixPathName(mentry->fPic->GetName());
2230 gSystem->ExpandPathName(picname);
2231 out << ",gClient->GetPicture(" << quote << picname << quote << ")";
2232 }
2233 out << ");" << std::endl;
2234 delete [] outext;
2235 break;
2236 case kMenuPopup:
2237 out << std::endl;
2238 out << " // cascaded menu " << quote << mentry->GetName() << quote <<std::endl;
2239 mentry->fPopup->SavePrimitive(out, option);
2240 text = mentry->GetName();
2241 lentext = mentry->fLabel->GetLength();
2242 hotpos = mentry->fLabel->GetHotPos();
2243 outext = new char[lentext+2];
2244 i=0;
2245 while (text && lentext) {
2246 if (i == hotpos-1) {
2247 outext[i] = '&';
2248 i++;
2249 }
2250 outext[i] = *text;
2251 i++; text++; lentext--;
2252 }
2253 outext[i]=0;
2254
2255 out << " " << GetName() << "->AddPopup(" << quote
2256 << outext << quote << "," << mentry->fPopup->GetName()
2257 << ");" << std::endl;
2258 delete [] outext;
2259 break;
2260 case kMenuLabel:
2261 out << " " << GetName() << "->AddLabel(" << quote
2262 << mentry->GetName() << quote;
2263 if (mentry->fPic) {
2264 out << ",gClient->GetPicture(" << quote
2265 << mentry->fPic->GetName()
2266 << quote << ")";
2267 }
2268 out << ");" << std::endl;
2269 break;
2270 case kMenuSeparator:
2271 out << " " << GetName() << "->AddSeparator();" << std::endl;
2272 break;
2273 }
2274
2275 if (!(mentry->GetStatus() & kMenuEnableMask)) {
2276 out<< " " << GetName() << "->DisableEntry(" << mentry->GetEntryId()
2277 << ");" << std::endl;
2278 }
2279 if (mentry->GetStatus() & kMenuHideMask) {
2280 out<< " " << GetName() << "->HideEntry(" << mentry->GetEntryId()
2281 << ");" << std::endl;
2282 }
2283 if (mentry->GetStatus() & kMenuCheckedMask) {
2284 out<< " " << GetName() << "->CheckEntry(" << mentry->GetEntryId()
2285 << ");" << std::endl;
2286 }
2287 if (mentry->GetStatus() & kMenuDefaultMask) {
2288 out<< " "<< GetName() << "->DefaultEntry(" << mentry->GetEntryId()
2289 << ");" << std::endl;
2290 }
2291 if (mentry->GetStatus() & kMenuRadioEntryMask) {
2292 if (hasradio) {
2293 r_last = mentry->GetEntryId();
2294 if (IsEntryRChecked(mentry->GetEntryId())) r_active = mentry->GetEntryId();
2295 }
2296 else {
2297 r_first = mentry->GetEntryId();
2298 hasradio = kTRUE;
2299 if (IsEntryRChecked(mentry->GetEntryId())) r_active = mentry->GetEntryId();
2300 }
2301 } else if (hasradio) {
2302 out << " " << GetName() << "->RCheckEntry(" << r_active << "," << r_first
2303 << "," << r_last << ");" << std::endl;
2304 hasradio = kFALSE;
2305 r_active = r_first = r_last = -1;
2306 }
2307 }
2308}
2309
2310////////////////////////////////////////////////////////////////////////////////
2311/// Save a title menu widget as a C++ statement(s) on output stream out.
2312
2313void TGMenuTitle::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2314{
2315 char quote = '"';
2316
2317 out << std::endl;
2318 out << " // " << quote << fLabel->GetString() << quote <<" menu" << std::endl;
2319
2320 fMenu->SavePrimitive(out, option);
2321
2322 const char *text = fLabel->GetString();
2323 Int_t lentext = fLabel->GetLength();
2324 Int_t hotpos = fLabel->GetHotPos();
2325 char *outext = new char[lentext+2];
2326 Int_t i=0;
2327 while (lentext) {
2328 if (i == hotpos-1) {
2329 outext[i] = '&';
2330 i++;
2331 }
2332 outext[i] = *text;
2333 i++; text++; lentext--;
2334 }
2335 outext[i]=0;
2336 out << " " << fParent->GetName() << "->AddPopup(" << quote << outext
2337 << quote << "," << fMenu->GetName();
2338
2339 delete [] outext;
2340}
2341
2342////////////////////////////////////////////////////////////////////////////////
2343/// Save a menu bar widget as a C++ statement(s) on output stream out.
2344
2345void TGMenuBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2346{
2347 out << std::endl;
2348 out << " // menu bar" << std::endl;
2349
2350 out << " TGMenuBar *";
2351 out << GetName() << " = new TGMenuBar(" << fParent->GetName()
2352 << "," << GetWidth() << "," << GetHeight() << "," << GetOptionString() << ");" << std::endl;
2353 if (option && strstr(option, "keep_names"))
2354 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
2355
2356 if (!fList) return;
2357
2358 TGFrameElement *el;
2359 TIter next(fList);
2360
2361 while ((el = (TGFrameElement *)next())) {
2362 el->fFrame->SavePrimitive(out, option);
2363 el->fLayout->SavePrimitive(out, option);
2364 out << ");" << std::endl;
2365 }
2366}
@ kGKeyPress
Definition GuiTypes.h:60
@ kButtonRelease
Definition GuiTypes.h:60
@ kButtonPress
Definition GuiTypes.h:60
@ kEnterNotify
Definition GuiTypes.h:61
@ kKeyRelease
Definition GuiTypes.h:60
const Mask_t kWAOverrideRedirect
Definition GuiTypes.h:149
const Mask_t kKeyLockMask
Definition GuiTypes.h:196
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
const Mask_t kKeyMod1Mask
typically the Alt key
Definition GuiTypes.h:198
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
const Mask_t kWASaveUnder
Definition GuiTypes.h:150
const Mask_t kAnyModifier
Definition GuiTypes.h:210
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
const Mask_t kButton1Mask
Definition GuiTypes.h:203
const Mask_t kGCFont
Definition GuiTypes.h:300
const Mask_t kPointerMotionMask
Definition GuiTypes.h:163
const Mask_t kKeyShiftMask
Definition GuiTypes.h:195
@ kRaisedFrame
Definition GuiTypes.h:384
@ kSunkenFrame
Definition GuiTypes.h:383
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kOwnBackground
Definition GuiTypes.h:391
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kKeyMod2Mask
typically mod on numeric keys
Definition GuiTypes.h:199
const Mask_t kLeaveWindowMask
Definition GuiTypes.h:168
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
const Mask_t kEnterWindowMask
Definition GuiTypes.h:167
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
@ kButton1
Definition GuiTypes.h:214
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
EKeySym
Definition KeySymbols.h:25
@ kKey_Right
Definition KeySymbols.h:42
@ kKey_Down
Definition KeySymbols.h:43
@ kKey_Up
Definition KeySymbols.h:41
@ kKey_Return
Definition KeySymbols.h:30
@ kKey_Left
Definition KeySymbols.h:40
@ kKey_Escape
Definition KeySymbols.h:26
@ kKey_Enter
Definition KeySymbols.h:31
int main()
Definition Prototype.cxx:12
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
bool Bool_t
Definition RtypesCore.h:63
long Longptr_t
Definition RtypesCore.h:82
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
#define gClient
Definition TGClient.h:156
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsTop
Definition TGLayout.h:27
@ kMenuRadioMask
Definition TGMenu.h:28
@ kMenuRadioEntryMask
Definition TGMenu.h:30
@ kMenuHideMask
Definition TGMenu.h:29
@ kMenuCheckedMask
Definition TGMenu.h:27
@ kMenuActiveMask
Definition TGMenu.h:24
@ kMenuDefaultMask
Definition TGMenu.h:26
@ kMenuEnableMask
Definition TGMenu.h:25
@ kMenuEntry
Definition TGMenu.h:38
@ kMenuSeparator
Definition TGMenu.h:36
@ kMenuPopup
Definition TGMenu.h:39
@ kMenuLabel
Definition TGMenu.h:37
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Option_t Option_t TPoint TPoint const char text
#define ClassImpQ(name)
Definition TQObject.h:283
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
#define gVirtualX
Definition TVirtualX.h:337
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kCM_MENU
@ kCM_MENUSELECT
@ kC_COMMAND
#define snprintf
Definition civetweb.c:1540
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:234
void RegisterPopup(TGWindow *w)
Add a popup menu to the list of popups.
Definition TGClient.cxx:533
const TGResourcePool * GetResourcePool() const
Definition TGClient.h:124
TGWindow * GetWindowById(Window_t sw) const
Find a TGWindow via its handle. If window is not found return 0.
Definition TGClient.cxx:594
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:372
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual TList * GetList() const
Definition TGFrame.h:310
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:312
Int_t MustCleanup() const override
Definition TGFrame.h:360
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
TList * fList
container of frame elements
Definition TGFrame.h:292
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1149
static TGLayoutHints * fgDefaultHints
Definition TGFrame.h:297
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
FontStruct_t GetFontStruct() const
Definition TGFont.h:184
TGLayoutHints * fLayout
Definition TGLayout.h:114
TGFrame * fFrame
Definition TGLayout.h:112
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
static Pixel_t GetDefaultSelectedBackground()
Get default selected frame background.
Definition TGFrame.cxx:696
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:339
static const TGGC & GetBlackGC()
Get black graphics context.
Definition TGFrame.cxx:735
UInt_t fOptions
frame options
Definition TGFrame.h:94
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
UInt_t fHeight
frame height
Definition TGFrame.h:88
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a frame widget as a C++ statement(s) on output stream out.
Definition TGFrame.cxx:3230
Int_t fBorderWidth
frame border width
Definition TGFrame.h:93
TGDimension GetSize() const
Definition TGFrame.h:230
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:430
virtual Pixel_t GetForeground() const
Return frame foreground color.
Definition TGFrame.cxx:303
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:755
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:593
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2506
void UnmapWindow() override
unmap window
Definition TGFrame.h:206
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:645
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:765
UInt_t fWidth
frame width
Definition TGFrame.h:87
virtual Bool_t HandleMotion(Event_t *)
Definition TGFrame.h:164
UInt_t GetHeight() const
Definition TGFrame.h:225
virtual void Layout()
Definition TGFrame.h:199
virtual Pixel_t GetBackground() const
Definition TGFrame.h:192
UInt_t GetWidth() const
Definition TGFrame.h:224
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:775
void MapRaised() override
map raised
Definition TGFrame.h:205
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
TGHotString is a string with a "hot" character underlined.
Definition TGString.h:42
void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y) override
Draw a hot string and underline the hot character.
Definition TGString.cxx:175
Int_t GetHotPos() const
Definition TGString.h:58
Int_t GetHotChar() const
Definition TGString.h:57
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Int_t GetPadRight() const
Definition TGLayout.h:86
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save layout hints as a C++ statement(s) on output stream out.
Definition TGLayout.cxx:975
ULong_t GetLayoutHints() const
Definition TGLayout.h:82
Int_t GetPadLeft() const
Definition TGLayout.h:85
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
The TGMenu.h header contains all different menu classes.
Definition TGMenu.h:282
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a menu bar widget as a C++ statement(s) on output stream out.
Definition TGMenu.cxx:2345
TGPopupMenu * fMenuMore
extra >> menu
Definition TGMenu.h:293
virtual TGPopupMenu * RemovePopup(const char *s)
Remove popup menu from menu bar.
Definition TGMenu.cxx:561
Bool_t fStick
stick mode (popup menu stays sticked on screen)
Definition TGMenu.h:290
~TGMenuBar() override
Delete menu bar object.
Definition TGMenu.cxx:155
Bool_t HandleMotion(Event_t *event) override
Handle a mouse motion event in a menu bar.
Definition TGMenu.cxx:590
virtual void AddFrameBefore(TGFrame *f, TGLayoutHints *l=nullptr, TGPopupMenu *before=nullptr)
Private version of AddFrame for menubar, to make sure that we indeed only add TGMenuTitle objects to ...
Definition TGMenu.cxx:503
virtual void BindHotKey(Int_t keycode, Bool_t on=kTRUE)
If on kTRUE bind hot keys, otherwise remove key binding.
Definition TGMenu.cxx:383
Bool_t fWithExt
indicates whether the >> menu is shown or not
Definition TGMenu.h:295
TGMenuTitle * fCurrent
current menu title
Definition TGMenu.h:287
virtual TGPopupMenu * GetPopup(const char *s)
Return popup menu with the specified name.
Definition TGMenu.cxx:540
static TClass * Class()
Bool_t HandleButton(Event_t *event) override
Handle a mouse button event in a menubar.
Definition TGMenu.cxx:623
void Layout() override
Calculates whether the >> menu must be shown or not and which menu titles are hidden.
Definition TGMenu.cxx:193
TList * fTrash
garbage
Definition TGMenu.h:291
virtual void BindKeys(Bool_t on=kTRUE)
If on kTRUE bind arrow, popup menu hot keys, otherwise remove key bindings.
Definition TGMenu.cxx:337
void BindMenu(TGPopupMenu *subMenu, Bool_t on)
If on kTRUE bind subMenu hot keys, otherwise remove key bindings.
Definition TGMenu.cxx:355
TList * fOutLayouts
keeps trace of layouts of hidden menus
Definition TGMenu.h:296
TGFrameElement * GetLastOnLeft()
Returns the last visible menu title on the left of the '>>' in the menu bar.
Definition TGMenu.cxx:268
void PopupConnection()
Connects the corresponding cascaded menu to the proper slots, according to the highlighted menu entry...
Definition TGMenu.cxx:289
TList * fNeededSpace
keeps trace of space needed for hidden menus
Definition TGMenu.h:297
Cursor_t fDefaultCursor
right pointing cursor
Definition TGMenu.h:289
TGMenuBar(const TGMenuBar &)=delete
Bool_t fKeyNavigate
kTRUE if arrow key navigation is on
Definition TGMenu.h:292
TGLayoutHints * fMenuBarMoreLayout
layout of the extra menu
Definition TGMenu.h:294
TList * fTitles
list of menu titles
Definition TGMenu.h:288
Bool_t HandleKey(Event_t *event) override
Handle keyboard events in a menu bar.
Definition TGMenu.cxx:686
virtual void AddTitle(TGMenuTitle *title, TGLayoutHints *l, TGPopupMenu *before=nullptr)
Add popup via created before menu title.
Definition TGMenu.cxx:435
friend class TGPopupMenu
Definition TGMenu.h:284
virtual void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l, TGPopupMenu *before=nullptr)
Add popup menu to menu bar.
Definition TGMenu.cxx:418
This class contains all information about a menu entry.
Definition TGMenu.h:57
TGPopupMenu * GetPopup() const
Definition TGMenu.h:88
Int_t fEx
Definition TGMenu.h:67
const char * GetShortcutText() const
Definition TGMenu.h:85
Int_t fStatus
entry status (OR of EMenuEntryState)
Definition TGMenu.h:66
Int_t fEntryId
the entry id (used for event processing)
Definition TGMenu.h:63
TGHotString * fLabel
menu entry label
Definition TGMenu.h:69
TGHotString * GetLabel() const
Definition TGMenu.h:89
const char * GetName() const override
Returns name of object.
Definition TGMenu.h:84
UInt_t fEw
Definition TGMenu.h:68
virtual Int_t GetStatus() const
Definition TGMenu.h:86
const TGPicture * fPic
menu entry icon
Definition TGMenu.h:71
TGString * fShortcut
menu entry shortcut
Definition TGMenu.h:70
void * fUserData
pointer to user data structure
Definition TGMenu.h:64
Int_t fEy
position of entry
Definition TGMenu.h:67
EMenuEntryType GetType() const
Definition TGMenu.h:87
EMenuEntryType fType
type of entry
Definition TGMenu.h:65
UInt_t fEh
width and height of entry
Definition TGMenu.h:68
TGPopupMenu * fPopup
pointer to popup menu (in case of cascading menus)
Definition TGMenu.h:72
Int_t GetEntryId() const
Definition TGMenu.h:83
This class creates a menu title.
Definition TGMenu.h:234
const char * GetName() const override
Returns name of object.
Definition TGMenu.h:274
TGHotString * fLabel
menu title
Definition TGMenu.h:238
static const TGGC * fgDefaultGC
Definition TGMenu.h:251
void * fTitleData
user data associated with selected item
Definition TGMenu.h:240
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Definition TGMenu.cxx:2144
TGPopupMenu * fMenu
attached popup menu
Definition TGMenu.h:237
void DoRedraw() override
Draw a menu title.
Definition TGMenu.cxx:2088
Int_t fHkeycode
hot key code
Definition TGMenu.h:242
virtual void SetState(Bool_t state)
Set state of menu title.
Definition TGMenu.cxx:2059
GContext_t fNormGC
Definition TGMenu.h:245
static const TGFont * fgDefaultFont
Definition TGMenu.h:249
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Definition TGMenu.cxx:2154
Int_t GetHotKeyCode() const
Definition TGMenu.h:272
static const TGGC * fgDefaultSelectedGC
Definition TGMenu.h:250
TGPopupMenu * GetMenu() const
Definition TGMenu.h:273
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a title menu widget as a C++ statement(s) on output stream out.
Definition TGMenu.cxx:2313
static const TGGC & GetDefaultSelectedGC()
Return default selection graphics context in use.
Definition TGMenu.cxx:2164
TGMenuTitle(const TGMenuTitle &)=delete
virtual void DoSendMessage()
Send final selected menu item to be processed.
Definition TGMenu.cxx:2131
Pixel_t fTextColor
text color
Definition TGMenu.h:244
GContext_t fSelGC
normal and selection graphics contexts
Definition TGMenu.h:245
Bool_t fState
menu title state (active/not active)
Definition TGMenu.h:241
FontStruct_t fFontStruct
font
Definition TGMenu.h:243
Int_t fTitleId
id of selected menu item
Definition TGMenu.h:239
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t GetId() const
Definition TGObject.h:41
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
void Draw(Option_t *="") override
Default Draw method for all objects.
Definition TGPicture.h:46
const char * GetName() const override
Returns name of object.
Definition TGPicture.h:51
UInt_t GetWidth() const
Definition TGPicture.h:52
This class creates a popup menu object.
Definition TGMenu.h:110
virtual void PoppedUp()
Definition TGMenu.h:216
Bool_t HandleCrossing(Event_t *event) override
Handle pointer crossing event in popup menu.
Definition TGMenu.cxx:1367
TList * fEntryList
list of menu entries
Definition TGMenu.h:117
virtual void HideEntry(Int_t id)
Hide entry (hidden entries are not shown in the menu).
Definition TGMenu.cxx:1751
virtual void DefaultEntry(Int_t id)
Set default entry (default entries are drawn with bold text).
Definition TGMenu.cxx:1689
TGPopupMenu(const TGPopupMenu &)=delete
Bool_t fPoppedUp
true if menu is currently popped up
Definition TGMenu.h:121
virtual void AddLabel(TGHotString *s, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu label to the menu.
Definition TGMenu.cxx:1095
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a popup menu widget as a C++ statement(s) on output stream out.
Definition TGMenu.cxx:2174
static const TGGC * fgDefaultGC
Definition TGMenu.h:139
TGMenuEntry * fCurrent
currently selected menu entry
Definition TGMenu.h:118
void Activate(Bool_t) override
Definition TGMenu.h:209
virtual TGMenuEntry * GetEntry(Int_t id)
Find entry with specified id.
Definition TGMenu.cxx:1897
static const TGGC & GetDefaultSelectedGC()
Return the selection graphics context in use.
Definition TGMenu.cxx:1974
Cursor_t fDefaultCursor
right pointing cursor
Definition TGMenu.h:131
static const TGGC * fgDefaultSelectedBackgroundGC
Definition TGMenu.h:141
virtual Bool_t IsEntryChecked(Int_t id)
Return true if menu item is checked.
Definition TGMenu.cxx:1845
UInt_t fMenuHeight
height of popup menu
Definition TGMenu.h:124
virtual Bool_t IsEntryRChecked(Int_t id)
Return true if menu item has radio check mark.
Definition TGMenu.cxx:1878
virtual void CheckEntryByData(void *user_data)
Check a menu entry (i.e.
Definition TGMenu.cxx:1795
TGSplitButton * fSplitButton
split button (if any)
Definition TGMenu.h:134
virtual void SetMenuBar(TGMenuBar *bar)
Definition TGMenu.h:207
GContext_t fNormGC
normal drawing graphics context
Definition TGMenu.h:126
void DoRedraw() override
Draw popup menu.
Definition TGMenu.cxx:1492
GContext_t fSelGC
graphics context for drawing selections
Definition TGMenu.h:127
virtual void Highlighted(Int_t id)
Definition TGMenu.h:218
static const TGGC & GetDefaultGC()
Return default graphics context.
Definition TGMenu.cxx:1964
void DrawBorder() override
Draw border round popup menu.
Definition TGMenu.cxx:1604
virtual void UnCheckEntries()
Uncheck all entries.
Definition TGMenu.cxx:1819
virtual void AddPopup(TGHotString *s, TGPopupMenu *popup, TGMenuEntry *before=nullptr, const TGPicture *p=nullptr)
Add a (cascading) popup menu to a popup menu.
Definition TGMenu.cxx:1152
static FontStruct_t GetDefaultFontStruct()
Return the default font structure in use.
Definition TGMenu.cxx:1994
static const TGGC * fgDefaultSelectedGC
Definition TGMenu.h:140
static const TGFont * fgDefaultFont
Definition TGMenu.h:137
virtual void CheckEntry(Int_t id)
Check a menu entry (i.e. add a check mark in front of it).
Definition TGMenu.cxx:1782
UInt_t fEntrySep
separation distance between entries
Definition TGMenu.h:135
TGMenuBar * fMenuBar
menu bar (if any)
Definition TGMenu.h:133
virtual void Reposition()
Reposition entries in popup menu.
Definition TGMenu.cxx:1209
Bool_t HandleTimer(TTimer *t) override
If TPopupDelayTimer times out popup cascading popup menu (if it is still the current entry).
Definition TGMenu.cxx:1467
virtual void DisableEntry(Int_t id)
Disable entry (disabled entries appear in a sunken relieve).
Definition TGMenu.cxx:1724
virtual void DrawEntry(TGMenuEntry *entry)
Draw popup menu entry.
Definition TGMenu.cxx:1506
virtual void EnableEntry(Int_t id)
Enable entry. By default entries are enabled.
Definition TGMenu.cxx:1705
virtual void UnCheckEntryByData(void *user_data)
Uncheck a menu entry (i.e.
Definition TGMenu.cxx:1833
virtual void PoppedDown()
Definition TGMenu.h:217
virtual Bool_t IsEntryHidden(Int_t id)
Return true if menu entry is hidden.
Definition TGMenu.cxx:1768
TTimer * fDelay
delay before popping up cascading menu
Definition TGMenu.h:125
UInt_t fXl
Max width of all menu entries.
Definition TGMenu.h:122
FontStruct_t fFontStruct
font to draw menu entries
Definition TGMenu.h:129
virtual void UnCheckEntry(Int_t id)
Uncheck menu entry (i.e. remove check mark).
Definition TGMenu.cxx:1807
virtual Int_t EndMenu(void *&userData)
Close menu and return ID of selected menu item.
Definition TGMenu.cxx:1289
virtual TGMenuEntry * GetCurrent() const
Definition TGMenu.h:198
virtual void DeleteEntry(Int_t id)
Delete entry with specified id from menu.
Definition TGMenu.cxx:1926
static FontStruct_t GetHilightFontStruct()
Return the font structure in use for highlighted menu entries.
Definition TGMenu.cxx:2004
const TGWindow * fMsgWindow
window which handles menu events
Definition TGMenu.h:132
static const TGGC & GetDefaultSelectedBackgroundGC()
Return the selection background graphics context in use.
Definition TGMenu.cxx:1984
virtual void AddSeparator(TGMenuEntry *before=nullptr)
Add a menu separator to the menu.
Definition TGMenu.cxx:1060
Bool_t fStick
stick mode (popup menu stays sticked on screen)
Definition TGMenu.h:119
FontStruct_t fHifontStruct
font to draw highlighted entries
Definition TGMenu.h:130
void DrawRCheckMark(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b)
Draw radio check mark. Used for radio button type menu entries.
Definition TGMenu.cxx:1670
void DrawCheckMark(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b)
Draw check mark. Used for checked button type menu entries.
Definition TGMenu.cxx:1651
virtual void RCheckEntry(Int_t id, Int_t IDfirst, Int_t IDlast)
Radio-select entry (note that they cannot be unselected, the selection must be moved to another entry...
Definition TGMenu.cxx:1860
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu entry.
Definition TGMenu.cxx:990
UInt_t fMenuWidth
width of popup menu
Definition TGMenu.h:123
virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
Popup a popup menu.
Definition TGMenu.cxx:1241
~TGPopupMenu() override
Delete a popup menu.
Definition TGMenu.cxx:975
const TList * GetListOfEntries() const
Definition TGMenu.h:200
virtual void Activated(Int_t id)
Definition TGMenu.h:219
GContext_t fSelbackGC
graphics context for drawing selection background
Definition TGMenu.h:128
Bool_t HandleMotion(Event_t *event) override
Handle pointer motion event in popup menu.
Definition TGMenu.cxx:1394
Bool_t HandleButton(Event_t *event) override
Handle button event in the popup menu.
Definition TGMenu.cxx:1338
static const TGFont * fgHilightFont
Definition TGMenu.h:138
Bool_t fHasGrab
true if menu has grabbed pointer
Definition TGMenu.h:120
void DrawTrianglePattern(GContext_t gc, Int_t l, Int_t t, Int_t r, Int_t b)
Draw triangle pattern.
Definition TGMenu.cxx:1631
virtual Bool_t IsEntryEnabled(Int_t id)
Return true if menu entry is enabled.
Definition TGMenu.cxx:1736
Cursor_t GetGrabCursor() const
Bool_t fKeyNavigate
kTRUE if key navigation is being used
Definition TGButton.h:404
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
Int_t GetLength() const
Definition TGString.h:29
const char * GetString() const
Definition TGString.h:30
virtual void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y)
Draw string.
Definition TGString.cxx:56
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition TGWindow.cxx:152
virtual void RequestFocus()
request focus
Definition TGWindow.cxx:232
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
virtual void DestroyWindow()
destroy window
Definition TGWindow.cxx:192
const TGWindow * GetParent() const
Definition TGWindow.h:83
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
void Reset()
A doubly linked list.
Definition TList.h:38
TObject * After(const TObject *obj) const override
Returns the object after object obj.
Definition TList.cxx:328
TObject * Before(const TObject *obj) const override
Returns the object before object obj.
Definition TList.cxx:369
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
void Add(TObject *obj) override
Definition TList.h:83
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition TList.cxx:150
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:691
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:657
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
Definition TList.cxx:194
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
Named parameter, streamable and storable.
Definition TParameter.h:35
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
Bool_t Notify() override
Notify when timer times out and reset the timer.
Definition TGMenu.cxx:109
TGPopupMenu * fPopup
Definition TGMenu.cxx:100
TPopupDelayTimer(TGPopupMenu *p, Long_t ms)
Definition TGMenu.cxx:102
TQConnection class is an internal class, used in the object communication mechanism.
TList * GetListOfSignals() const
Definition TQObject.h:88
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:869
Bool_t Disconnect(const char *signal=nullptr, void *receiver=nullptr, const char *slot=nullptr)
Disconnects signal of this object from slot of receiver.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
const char * Data() const
Definition TString.h:376
TString & Remove(Ssiz_t pos)
Definition TString.h:685
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1274
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition TSystem.cxx:1063
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:471
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:159
void Remove() override
Definition TTimer.h:86
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:178
Window_t fWindow
window reported event is relative to
Definition GuiTypes.h:176
UInt_t fState
key or button mask
Definition GuiTypes.h:181
Int_t fX
Definition GuiTypes.h:178
UInt_t fCode
key or button code
Definition GuiTypes.h:180
Graphics context structure.
Definition GuiTypes.h:224
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:251
FontH_t fFont
default text font for text operations
Definition GuiTypes.h:242
Point structure (maps to the X11 XPoint structure)
Definition GuiTypes.h:356
Used for drawing line segments (maps to the X11 XSegments structure)
Definition GuiTypes.h:351
Short_t fY2
Definition GuiTypes.h:352
Short_t fX1
Definition GuiTypes.h:352
Short_t fX2
Definition GuiTypes.h:352
Short_t fY1
Definition GuiTypes.h:352
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:93
Bool_t fOverrideRedirect
boolean value for override-redirect
Definition GuiTypes.h:107
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:110
Bool_t fSaveUnder
should bits under be saved (popups)?
Definition GuiTypes.h:104
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4