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