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