Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRootContextMenu.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 12/02/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/** \class TRootContextMenu
14 \ingroup guiwidgets
15
16This class provides an interface to context sensitive popup menus.
17These menus pop up when the user hits the right mouse button, and
18are destroyed when the menu pops downs.
19The picture below shows a canvas with a pop-up menu.
20
21*/
22
23
24#include "TRootContextMenu.h"
25#include "TROOT.h"
26#include "TGClient.h"
27#include "TEnv.h"
28#include "TList.h"
29#include "TObjArray.h"
30#include "TContextMenu.h"
31#include "TMethod.h"
32#include "TMethodArg.h"
33#include "TMethodCall.h"
34#include "TClass.h"
35#include "TVirtualX.h"
36#include "TCanvas.h"
37#include "TDataMember.h"
38#include "TToggle.h"
39#include "TRootDialog.h"
40#include "TDataType.h"
41#include "TBrowser.h"
42#include "TRootCanvas.h"
43#include "TRootBrowser.h"
44#include "TClassMenuItem.h"
45#include "TObjectSpy.h"
46#include "KeySymbols.h"
47#include "RConfigure.h"
48#include "strlcpy.h"
49#include "snprintf.h"
50
52 kToggleStart = 1000, // first id of toggle menu items
53 kToggleListStart = 2000, // first id of toggle list menu items
54 kUserFunctionStart = 3000 // first id of user added functions/methods, etc...
55};
56
57
59
60////////////////////////////////////////////////////////////////////////////////
61/// Create context menu.
62
64 : TGPopupMenu(gClient->GetDefaultRoot()), TContextMenuImp(c)
65{
66 fDialog = 0;
67 fTrash = new TList;
68
70 gROOT->GetListOfCleanups()->Add(this);
71 // Context menu handles its own messages
72 Associate(this);
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Delete a context menu.
77
79{
80 gROOT->GetListOfCleanups()->Remove(this);
81 delete fDialog;
82 if (fTrash) fTrash->Delete();
83 delete fTrash;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Display context popup menu for currently selected object.
88
90{
91 if (fClient->IsEditable()) return;
92
93 // delete menu items releated to previous object and reset menu size
95 fCurrent = 0;
96 if (fTrash) fTrash->Delete();
97 fMenuHeight = 6;
98 fMenuWidth = 8;
99
100 // delete previous dialog
101 if (fDialog) {
102 delete fDialog;
103 fDialog = 0;
104 }
105
106 // add menu items to popup menu
108
109 int xx, yy, topx = 0, topy = 0;
110 UInt_t w, h;
111
114 topx, topy, w, h);
115
116 xx = topx + x + 1;
117 yy = topy + y + 1;
118
119#ifdef R__HAS_COCOA
120 //Context menu must be transient for a canvas, otherwise it's possible
121 //to break the z-order (for example, using alt-tab to switch between
122 //different aplications). This hint works ONLY for canvas though
123 //(otherwise selected canvas is null).
124 TGWindow *parent = 0;
126 parent = dynamic_cast<TGWindow *>(pad->GetCanvasImp());
127 else if ((pad = fContextMenu->GetSelectedPad()) && pad->GetCanvasImp())
128 parent = dynamic_cast<TGWindow *>(pad->GetCanvasImp());
129 else if (TBrowser * const browser = fContextMenu->GetBrowser())
130 parent = dynamic_cast<TGWindow *>(browser->GetBrowserImp());
131
132 if (parent)
133 gVirtualX->SetWMTransientHint(GetId(), parent->GetId());
134#endif
135
136 PlaceMenu(xx, yy, kTRUE, kTRUE);
137 // add some space for the right-side '?' (help)
138 fMenuWidth += 5;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Decodes the Hierarchy="Level0/Level1/Level2/..." statement from the comment field
144/// and returns the - if needed - created sub menu "Level0/Level1"
145/// Returns the last component in last_component.
146
147TGPopupMenu * TRootContextMenu::FindHierarchy(const char *commentstring, TString & last_component)
148{
149 TString cmd(commentstring);
151 TString hierarchy;
152 TGPopupMenu *currentMenu = 0;
153
154 // search for arguments to the MENU statement
155 // strcpy(cmd,commentstring);
156 Ssiz_t opt_ptr;
157 if ((opt_ptr=cmd.Index("*MENU={")) != kNPOS ||
158 (opt_ptr=cmd.Index("*SUBMENU={"))!= kNPOS ||
159 (opt_ptr=cmd.Index("*TOGGLE={")) != kNPOS ) {
160
161 Ssiz_t start = cmd.Index("{",opt_ptr) + 1;
162 Ssiz_t end = cmd.Index("}",start);
163 option = cmd(start,end - start);
164
165 // Look for Hierarchy token
166 TObjArray * array = option.Tokenize(";");
167 TIter iter(array);
168 TObject *obj;
169 while((obj = iter())) {
170 TString token(obj->GetName());
171 if (token.Index("Hierarchy=\"") != kNPOS) {
172 Ssiz_t tstart = token.Index("\"") + 1;
173 Ssiz_t tend = token.Index("\"",tstart+1);
174 if (tend == kNPOS) continue;
175 hierarchy = token(tstart,tend - tstart);
176 }
177 }
178 delete array;
179 }
180
181 // Build Hierarchy
182 currentMenu = this;
183 TObjArray * array = hierarchy.Tokenize("/");
184 TIter iter(array);
185 TObject *obj = iter();
186 while(obj) {
187 last_component = obj->GetName();
188 obj = iter();
189 if (obj) {
190 TGMenuEntry *ptr;
191 TIter next(currentMenu->GetListOfEntries());
192 // Search for popup with corresponding name
193 while ((ptr = (TGMenuEntry *) next()) &&
194 (ptr->GetType() != kMenuPopup ||
195 last_component.CompareTo(ptr->GetName()))) { }
196 if (ptr)
197 currentMenu = ptr->GetPopup();
198 else {
199 TGPopupMenu *r = new TGPopupMenu(gClient->GetDefaultRoot());
200 // Alphabetical ordering
202 TIter next2(currentMenu->GetListOfEntries());
203 // Search for popup with corresponding name
204 while ((ptr2 = (TGMenuEntry *) next2()) &&
205 (ptr2->GetType() != kMenuPopup ||
206 last_component.CompareTo(ptr2->GetName()) > 0 )) { }
207
208 currentMenu->AddPopup(last_component, r,ptr2);
209 currentMenu = r;
210 fTrash->Add(r);
211 last_component = obj->GetName();
212 }
213 }
214 }
215
216 delete array;
217 return currentMenu;
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Add a entry to current menu with alphabetical ordering.
222
223void TRootContextMenu::AddEntrySorted(TGPopupMenu *currentMenu, const char *s, Int_t id, void *ud,
224 const TGPicture *p , Bool_t sorted)
225{
226 TGMenuEntry *ptr2 = 0;
227 if (sorted) {
228 TIter next(currentMenu->GetListOfEntries());
229 // Search for popup with corresponding name
230 while ((ptr2 = (TGMenuEntry *) next()) &&
231 (ptr2->GetType() != kMenuEntry ||
232 strcmp(ptr2->GetName(), s)<0 )) { }
233 }
234 currentMenu->AddEntry(s,id,ud,p,ptr2);
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Create the context menu depending on the selected object.
239
241{
242 if (!object || fClient->IsEditable()) return;
243
244 int entry = 0, toggle = kToggleStart, togglelist = kToggleListStart;
245 int userfunction = kUserFunctionStart;
246
247 // Add a title
249 AddSeparator();
250
251 // Get list of menu items from the selected object's class
252 TList *menuItemList = object->IsA()->GetMenuList();
253
254 TClassMenuItem *menuItem;
255 TIter nextItem(menuItemList);
256
257 while ((menuItem = (TClassMenuItem*) nextItem())) {
258 switch (menuItem->GetType()) {
260 {
262 if (last && last->GetType() != kMenuSeparator)
263 AddSeparator();
264 break;
265 }
267 {
268 // Standard list of class methods. Rebuild from scratch.
269 // Get linked list of objects menu items (i.e. member functions
270 // with the token *MENU in their comment fields.
271 TList *methodList = new TList;
272 object->IsA()->GetMenuItems(methodList);
273
274 TMethod *method;
275 TClass *classPtr = 0;
276 TIter next(methodList);
277 Bool_t needSep = kFALSE;
278
279 while ((method = (TMethod*) next())) {
280 if (classPtr != method->GetClass()) {
281 needSep = kTRUE;
282 classPtr = method->GetClass();
283 }
284
285 TDataMember *m;
286 EMenuItemKind menuKind = method->IsMenuItem();
287 TGPopupMenu *currentMenu = 0;
288 TString last_component;
289
290 switch (menuKind) {
291 case kMenuDialog:
292 // search for arguments to the MENU statement
293 currentMenu = FindHierarchy(method->GetCommentString(),last_component);
294 if (needSep && currentMenu == this) {
295 AddSeparator();
296 needSep = kFALSE;
297 }
298 AddEntrySorted(currentMenu,last_component.Length() ? last_component.Data() : method->GetName(), entry++, method,0,currentMenu != this);
299 break;
300 case kMenuSubMenu:
301 if ((m = method->FindDataMember())) {
302
303 // search for arguments to the MENU statement
304 currentMenu = FindHierarchy(method->GetCommentString(),last_component);
305
306 if (m->GetterMethod()) {
307 TGPopupMenu *r = new TGPopupMenu(gClient->GetDefaultRoot());
308 if (needSep && currentMenu == this) {
309 AddSeparator();
310 needSep = kFALSE;
311 }
312 if (last_component.Length()) {
313 currentMenu->AddPopup(last_component, r);
314 } else {
315 currentMenu->AddPopup(method->GetName(), r);
316 }
317 fTrash->Add(r);
318 TIter nxt(m->GetOptions());
319 TOptionListItem *it;
320 while ((it = (TOptionListItem*) nxt())) {
321 const char *name = it->fOptName;
322 Long_t val = it->fValue;
323
324 TToggle *t = new TToggle;
325 t->SetToggledObject(object, method);
326 t->SetOnValue(val);
327 fTrash->Add(t);
328
329 r->AddEntry(name, togglelist++, t);
330 if (t->GetState())
331 r->CheckEntry(togglelist-1);
332 }
333 } else {
334 if (needSep && currentMenu == this) {
335 AddSeparator();
336 needSep = kFALSE;
337 }
338 AddEntrySorted(currentMenu,last_component.Length() ? last_component.Data() : method->GetName(), entry++, method,0,currentMenu != this);
339 }
340 }
341 break;
342
343 case kMenuToggle:
344 {
345 TToggle *t = new TToggle;
346 t->SetToggledObject(object, method);
347 t->SetOnValue(1);
348 fTrash->Add(t);
349 // search for arguments to the MENU statement
350 currentMenu = FindHierarchy(method->GetCommentString(),last_component);
351 if (needSep && currentMenu == this) {
352 AddSeparator();
353 needSep = kFALSE;
354 }
355 AddEntrySorted(currentMenu,last_component.Length() ? last_component.Data() : method->GetName(), toggle++, t,0,currentMenu != this);
356 if (t->GetState()) currentMenu->CheckEntry(toggle-1);
357 }
358 break;
359
360 default:
361 break;
362 }
363 }
364 delete methodList;
365 }
366 break;
368 {
369 const char* menuItemTitle = menuItem->GetTitle();
370 if (menuItem->IsToggle()) {
371 TMethod* method =
372 object->IsA()->GetMethodWithPrototype(menuItem->GetFunctionName(),menuItem->GetArgs());
373 if (method) {
374 TToggle *t = new TToggle;
375 t->SetToggledObject(object, method);
376 t->SetOnValue(1);
377 fTrash->Add(t);
378
379 if (strlen(menuItemTitle)==0) menuItemTitle = method->GetName();
380 AddEntry(menuItemTitle, toggle++, t);
381 if (t->GetState()) CheckEntry(toggle-1);
382 }
383 } else {
384 if (strlen(menuItemTitle)==0) menuItemTitle = menuItem->GetFunctionName();
385 AddEntry(menuItemTitle,userfunction++,menuItem);
386 }
387 }
388 break;
389 default:
390 break;
391 }
392 }
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Create dialog object with OK and Cancel buttons. This dialog
397/// prompts for the arguments of "method".
398
400{
401 Dialog(object,(TFunction*)method);
402}
403
404////////////////////////////////////////////////////////////////////////////////
405/// Create dialog object with OK and Cancel buttons. This dialog
406/// prompts for the arguments of "function".
407/// function may be a global function or a method
408
410{
411 Int_t selfobjpos;
412
413 if (!function) return;
414
415 // Position, if it exists, of the argument that correspond to the object itself
418 else selfobjpos = -1;
419
420 const TGWindow *w;
423 // Embedded canvas has no canvasimp that is a TGFrame
424 // coverity[returned_null]
425 // coverity[dereference]
426 if (c->GetCanvasImp()->IsA()->InheritsFrom(TGFrame::Class())) {
427 w = fClient->GetWindowById(gVirtualX->GetWindowID(c->GetCanvasID()));
428 if (!w) w = (TRootCanvas *) c->GetCanvasImp();
429 } else {
430 w = gClient->GetDefaultRoot();
431 }
432 } else if (fContextMenu->GetBrowser()) {
434 w = (TRootBrowser *) b->GetBrowserImp();
435 } else {
436 w = gClient->GetDefaultRoot();
437 }
439
440 // iterate through all arguments and create apropriate input-data objects:
441 // inputlines, option menus...
442 TMethodArg *argument = 0;
443
444 TIter next(function->GetListOfMethodArgs());
445 Int_t argpos = 0;
446
447 while ((argument = (TMethodArg *) next())) {
448 // Do not input argument for self object
449 if (selfobjpos != argpos) {
450 const char *argname = fContextMenu->CreateArgumentTitle(argument);
451 const char *type = argument->GetTypeName();
452 TDataType *datatype = gROOT->GetType(type);
453 const char *charstar = "char*";
454 char basictype[32];
455
456 if (datatype) {
457 strlcpy(basictype, datatype->GetTypeName(), 32);
458 } else {
460 if (strncmp(type, "enum", 4) && (cl && !(cl->Property() & kIsEnum)))
461 Warning("Dialog", "data type is not basic type, assuming (int)");
462 strlcpy(basictype, "int", 32);
463 }
464
465 if (strchr(argname, '*')) {
466 strlcat(basictype, "*",32);
467 if (!strncmp(type, "char", 4) || !strncmp(type, "Option_t", 8))
468 type = charstar;
469 else if (strstr(argname, "[default:")) {
470 // skip arguments that are pointers (but not char *)
471 // and have a default value
472 argpos++;
473 continue;
474 }
475 }
476
477 TDataMember *m = argument->GetDataMember();
478 if (m && object && m->GetterMethod(object->IsA())) {
479
480 // Get the current value and form it as a text:
481
482 char val[256];
483
484 if (!strncmp(basictype, "char*", 5)) {
485 char *tdefval;
486 m->GetterMethod()->Execute(object, "", &tdefval);
487 strlcpy(val, tdefval, sizeof(val));
488 } else if (!strncmp(basictype, "float", 5) ||
489 !strncmp(basictype, "double", 6)) {
490 Double_t ddefval;
491 m->GetterMethod()->Execute(object, "", ddefval);
492 snprintf(val,256, "%g", ddefval);
493 } else if (!strncmp(basictype, "char", 4) ||
494 !strncmp(basictype, "bool", 4) ||
495 !strncmp(basictype, "int", 3) ||
496 !strncmp(basictype, "long", 4) ||
497 !strncmp(basictype, "short", 5)) {
498 Longptr_t ldefval;
499 m->GetterMethod()->Execute(object, "", ldefval);
500 snprintf(val, 256, "%zi", (size_t)ldefval);
501 }
502
503 // Find out whether we have options ...
504 if (m->GetOptions()) {
505 Warning("Dialog", "option menu not yet implemented");
506#if 0
507 TMotifOptionMenu *o= new TMotifOptionMenu(argname);
508 TIter nextopt(opt);
509 TOptionListItem *it = 0;
510 while ((it = (TOptionListItem*) nextopt())) {
511 char *name = it->fOptName;
512 char *label = it->fOptLabel;
513 Long_t value = it->fValue;
514 if (value != -9999) {
515 char val[256];
516 snprintf(val,256, "%li", value);
517 o->AddItem(name, val);
518 }else
519 o->AddItem(name, label);
520 }
521 o->SetData(val);
522 fDialog->Add(o);
523#endif
524 } else {
525 // we haven't got options - textfield ...
526 fDialog->Add(argname, val, type);
527 }
528 } else { // if m not found ...
529
530 char val[256] = "";
531 const char *tval = argument->GetDefault();
532 if (tval && strlen(tval)) {
533 // Remove leading and trailing quotes
534 strlcpy(val, tval + (tval[0] == '"' ? 1 : 0), sizeof(val));
535 if (val[strlen(val)-1] == '"')
536 val[strlen(val)-1]= 0;
537 }
538 fDialog->Add(argname, val, type);
539 }
540 }
541 argpos++;
542 }
543
544 fDialog->Popup();
545}
546
547////////////////////////////////////////////////////////////////////////////////
548/// Draw context menu entry.
549
551{
552 int ty, offset;
553 static int max_ascent = 0, max_descent = 0;
554
556 // draw the ? (help) in the right side when highlighting a menu entry
557 if (entry->GetType() == kMenuEntry && (entry->GetStatus() & kMenuActiveMask)) {
558 if (max_ascent == 0) {
559 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
560 }
561 offset = (entry->GetEh() - (max_ascent + max_descent)) / 2;
562 ty = entry->GetEy() + max_ascent + offset - 1;
563 TGHotString s("&?");
564 s.Draw(fId, fSelGC, fMenuWidth-12, ty);
565 }
566}
567
568////////////////////////////////////////////////////////////////////////////////
569/// Handle button event in the context menu.
570
572{
573 int id;
574 void *ud = 0;
575
576 if ((event->fType == kButtonRelease) && (event->fX >= (Int_t)(fMenuWidth-15)) &&
577 (event->fX <= (Int_t)fMenuWidth)) {
578 id = EndMenu(ud);
579 if (fHasGrab) gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab
580 if (ud) {
581 // retrieve the highlighted function
582 TFunction *function = 0;
583 if (id < kToggleStart) {
584 TMethod *m = (TMethod *)ud;
585 function = (TFunction *)m;
586 } else if (id >= kToggleStart && id < kUserFunctionStart) {
587 TToggle *t = (TToggle *)ud;
588 TMethodCall *mc = (TMethodCall *)t->GetSetter();
589 function = (TFunction *)mc->GetMethod();
590 } else {
591 TClassMenuItem *mi = (TClassMenuItem *)ud;
592 function = gROOT->GetGlobalFunctionWithPrototype(mi->GetFunctionName());
593 }
594 if (function)
596 }
597 OnlineHelp();
598 return kTRUE;
599 }
600 return TGPopupMenu::HandleButton(event);
601}
602
603////////////////////////////////////////////////////////////////////////////////
604/// Handle pointer crossing event in context menu.
605
607{
608 if (event->fType == kLeaveNotify) {
609 // just to reset the mouse pointer...
610 HandleMotion(event);
611 }
612 return TGPopupMenu::HandleCrossing(event);
613}
614
615////////////////////////////////////////////////////////////////////////////////
616/// Handle pointer motion event in context menu.
617
619{
620 static int toggle = 0;
621 static Cursor_t handCur = kNone, rightCur = kNone;
623
624 if (handCur == kNone)
625 handCur = gVirtualX->CreateCursor(kHand);
626 if (rightCur == kNone)
627 rightCur = gVirtualX->CreateCursor(kArrowRight);
628
629 if (event->fType == kLeaveNotify) {
630 gVirtualX->ChangeActivePointerGrab(fId, mask, rightCur);
631 toggle = 0;
632 return kTRUE;
633 }
634 // change the cursot to a small hand when over the ? (help)
635 if ((event->fX >= (Int_t)(fMenuWidth-15)) && (event->fX <= (Int_t)fMenuWidth) &&
636 fCurrent && (fCurrent->GetType() == kMenuEntry)) {
637 if (toggle == 0) {
638 gVirtualX->ChangeActivePointerGrab(fId, mask, handCur);
639 toggle = 1;
640 }
641 }
642 else {
643 if (toggle == 1) {
644 gVirtualX->ChangeActivePointerGrab(fId, mask, rightCur);
645 toggle = 0;
646 }
647 }
648 return TGPopupMenu::HandleMotion(event);
649}
650
651////////////////////////////////////////////////////////////////////////////////
652/// Open the online help matching the actual class/method.
653
655{
656 TString clname;
657 TString cmd;
658 TString url = gEnv->GetValue("Browser.StartUrl", "http://root.cern.ch/root/html/");
659 if (url.EndsWith(".html", TString::kIgnoreCase)) {
660 if (url.Last('/') != kNPOS)
661 url.Remove(url.Last('/'));
662 }
663 if (!url.EndsWith("/")) {
664 url += '/';
665 }
667 if (obj) {
668 clname = obj->ClassName();
671 TMethod *method = obj->IsA()->GetMethodAllAny(smeth.Data());
672 if (method) clname = method->GetClass()->GetName();
673 url += clname;
674 url += ".html";
675 url += "#";
676 url += clname;
677 url += ":";
678 url += smeth.Data();
679 }
680 else {
681 url += clname;
682 url += ".html";
683 }
684 if (fDialog) delete fDialog;
685 fDialog = 0;
686 cmd = TString::Format("new TGHtmlBrowser(\"%s\", 0, 900, 300);", url.Data());
687 gROOT->ProcessLine(cmd.Data());
688 }
689}
690
691////////////////////////////////////////////////////////////////////////////////
692/// Handle context menu messages.
693
695{
696 TObjectSpy savedPad;
697 if (GetContextMenu()->GetSelectedPad()) {
698 savedPad.SetObject(gPad);
700 }
701
702 switch (GET_MSG(msg)) {
703
704 case kC_COMMAND:
705
706 switch (GET_SUBMSG(msg)) {
707
708 case kCM_MENU:
709
710 if (parm1 < kToggleStart) {
711 TMethod *m = (TMethod *) parm2;
713 } else if (parm1 >= kToggleStart && parm1 < kToggleListStart) {
714 TToggle *t = (TToggle *) parm2;
716 } else if (parm1 >= kToggleListStart && parm1<kUserFunctionStart) {
717 TToggle *t = (TToggle *) parm2;
718 if (t->GetState() == 0)
719 t->SetState(1);
720 } else {
721 TClassMenuItem *mi = (TClassMenuItem*)parm2;
722 GetContextMenu()->Action(mi);
723 }
724 break;
725
726 case kCM_BUTTON:
727 if (parm1 == 1) {
728 const char *args = fDialog->GetParameters();
729 GetContextMenu()->Execute((char *)args);
730 delete fDialog;
731 fDialog = nullptr;
732 }
733 if (parm1 == 2) {
734 const char *args = fDialog->GetParameters();
735 GetContextMenu()->Execute((char *)args);
736 }
737 if (parm1 == 3) {
738 delete fDialog;
739 fDialog = nullptr;
740 }
741 if (parm1 == 4) {
742 OnlineHelp();
743 }
744 break;
745
746 default:
747 break;
748 }
749 break;
750
751 case kC_TEXTENTRY:
752
753 switch (GET_SUBMSG(msg)) {
754
755 case kTE_ENTER:
756 {
757 const char *args = fDialog->GetParameters();
758 GetContextMenu()->Execute((char *)args);
759 delete fDialog;
760 fDialog = nullptr;
761 }
762 break;
763
764 default:
765 break;
766 }
767 break;
768
769 default:
770 break;
771 }
772
773 if (savedPad.GetObject()) gPad = (TVirtualPad*) savedPad.GetObject();
774
775 return kTRUE;
776}
777
778////////////////////////////////////////////////////////////////////////////////
779/// Close the context menu if the object is deleted in the
780/// RecursiveRemove() operation.
781
783{
784 void *ud;
785 if (obj == fContextMenu->GetSelectedCanvas())
787 if (obj == fContextMenu->GetSelectedPad())
789 if (obj == fContextMenu->GetSelectedObject()) {
790 // if the object being deleted is the one selected,
791 // ungrab the mouse pointer and terminate (close) the menu
793 if (fHasGrab)
794 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
795 EndMenu(ud);
796 }
797}
798
@ kButtonRelease
Definition GuiTypes.h:60
@ kLeaveNotify
Definition GuiTypes.h:61
@ kArrowRight
Definition GuiTypes.h:375
@ kHand
Definition GuiTypes.h:374
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
const Mask_t kPointerMotionMask
Definition GuiTypes.h:163
Handle_t Cursor_t
Cursor handle.
Definition GuiTypes.h:34
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
RooAbsReal & function()
long Longptr_t
Definition RtypesCore.h:82
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:124
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
@ kIsEnum
Definition TDictionary.h:68
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
#define gClient
Definition TGClient.h:156
@ kMenuActiveMask
Definition TGMenu.h:24
@ kMenuEntry
Definition TGMenu.h:38
@ kMenuSeparator
Definition TGMenu.h:36
@ kMenuPopup
Definition TGMenu.h:39
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
EMenuItemKind
Definition TMethod.h:31
@ kMenuSubMenu
Definition TMethod.h:35
@ kMenuDialog
Definition TMethod.h:33
@ kMenuToggle
Definition TMethod.h:34
#define gROOT
Definition TROOT.h:406
@ kToggleStart
@ kToggleListStart
@ kUserFunctionStart
#define gPad
#define gVirtualX
Definition TVirtualX.h:337
Int_t GET_MSG(Long_t val)
@ kCM_MENU
@ kTE_ENTER
@ kC_COMMAND
@ kCM_BUTTON
@ kC_TEXTENTRY
Int_t GET_SUBMSG(Long_t val)
#define snprintf
Definition civetweb.c:1540
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
TBrowserImp * GetBrowserImp() const
Definition TBrowser.h:94
The Canvas class.
Definition TCanvas.h:23
Describes one element of the context menu associated to a class The menu item may describe.
virtual const char * GetArgs() const
const char * GetTitle() const override
Returns title of object.
virtual const char * GetFunctionName() const
virtual Int_t GetType() const
virtual Bool_t IsToggle() const
virtual Int_t GetSelfObjectPos() const
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
TList * GetMenuList() const
Return the list of menu items associated with the class.
Definition TClass.cxx:4341
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Definition TClass.cxx:4456
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6086
void GetMenuItems(TList *listitems)
Returns list of methods accessible by context menu.
Definition TClass.cxx:3874
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4384
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2968
This class provides an interface to GUI independent context sensitive popup menus.
TContextMenu * fContextMenu
virtual TContextMenu * GetContextMenu() const
This class provides an interface to context sensitive popup menus.
virtual void SetCanvas(TVirtualPad *c)
virtual TVirtualPad * GetSelectedCanvas()
virtual void Action(TObject *object, TMethod *method)
Action to be performed when this menu item is selected.
virtual TFunction * GetSelectedMethod()
virtual TVirtualPad * GetSelectedPad()
virtual void SetPad(TVirtualPad *p)
virtual TClassMenuItem * GetSelectedMenuItem()
virtual void SetMethod(TFunction *m)
virtual void SetObject(TObject *o)
virtual TObject * GetSelectedObject()
virtual const char * CreateArgumentTitle(TMethodArg *argument)
Create string describing argument (for use in dialog box).
virtual TBrowser * GetBrowser()
virtual const char * CreateDialogTitle(TObject *object, TFunction *method)
Create title for dialog box retrieving argument values.
virtual const char * CreatePopupTitle(TObject *object)
Create title for popup menu.
void Execute(const char *method, const char *params, Int_t *error=nullptr) override
Execute method on this object with the given parameter string, e.g.
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
Basic data type descriptor (datatype information is obtained from CINT).
Definition TDataType.h:44
Int_t GetType() const
Definition TDataType.h:68
TString GetTypeName()
Get basic type of typedef, e,g.: "class TDirectory*" -> "TDirectory".
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
Bool_t IsEditable() const
Definition TGClient.h:89
TGWindow * GetWindowById(Window_t sw) const
Find a TGWindow via its handle. If window is not found return 0.
Definition TGClient.cxx:594
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:339
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
virtual UInt_t GetDefaultWidth() const
Definition TGFrame.h:190
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
static TClass * Class()
TGHotString is a string with a "hot" character underlined.
Definition TGString.h:42
void Draw(Drawable_t id, GContext_t gc, Int_t x, Int_t y) override
Draw a hot string and underline the hot character.
Definition TGString.cxx:175
This class contains all information about a menu entry.
Definition TGMenu.h:57
TGPopupMenu * GetPopup() const
Definition TGMenu.h:88
const char * GetName() const override
Returns name of object.
Definition TGMenu.h:84
Int_t GetEy() const
Definition TGMenu.h:92
virtual Int_t GetStatus() const
Definition TGMenu.h:86
EMenuEntryType GetType() const
Definition TGMenu.h:87
UInt_t GetEh() const
Definition TGMenu.h:94
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t GetId() const
Definition TGObject.h:41
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
This class creates a popup menu object.
Definition TGMenu.h:110
Bool_t HandleCrossing(Event_t *event) override
Handle pointer crossing event in popup menu.
Definition TGMenu.cxx:1367
TList * fEntryList
list of menu entries
Definition TGMenu.h:117
virtual void AddLabel(TGHotString *s, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu label to the menu.
Definition TGMenu.cxx:1095
TGMenuEntry * fCurrent
currently selected menu entry
Definition TGMenu.h:118
UInt_t fMenuHeight
height of popup menu
Definition TGMenu.h:124
GContext_t fSelGC
graphics context for drawing selections
Definition TGMenu.h:127
virtual void AddPopup(TGHotString *s, TGPopupMenu *popup, TGMenuEntry *before=nullptr, const TGPicture *p=nullptr)
Add a (cascading) popup menu to a popup menu.
Definition TGMenu.cxx:1152
virtual void CheckEntry(Int_t id)
Check a menu entry (i.e. add a check mark in front of it).
Definition TGMenu.cxx:1782
virtual void DrawEntry(TGMenuEntry *entry)
Draw popup menu entry.
Definition TGMenu.cxx:1506
FontStruct_t fFontStruct
font to draw menu entries
Definition TGMenu.h:129
virtual void Associate(const TGWindow *w)
Definition TGMenu.h:206
virtual Int_t EndMenu(void *&userData)
Close menu and return ID of selected menu item.
Definition TGMenu.cxx:1289
virtual void AddSeparator(TGMenuEntry *before=nullptr)
Add a menu separator to the menu.
Definition TGMenu.cxx:1060
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu entry.
Definition TGMenu.cxx:990
UInt_t fMenuWidth
width of popup menu
Definition TGMenu.h:123
virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
Popup a popup menu.
Definition TGMenu.cxx:1241
const TList * GetListOfEntries() const
Definition TGMenu.h:200
Bool_t HandleMotion(Event_t *event) override
Handle pointer motion event in popup menu.
Definition TGMenu.cxx:1394
Bool_t HandleButton(Event_t *event) override
Handle button event in the popup menu.
Definition TGMenu.cxx:1338
Bool_t fHasGrab
true if menu has grabbed pointer
Definition TGMenu.h:120
ROOT GUI Window base class.
Definition TGWindow.h:23
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:691
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
TClass * IsA() const override
Definition TList.h:110
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
const char * GetDefault() const
Get default value of method argument.
const char * GetTypeName() const
Get type of method argument, e.g.: "class TDirectory*" -> "TDirectory" Result needs to be used or cop...
TDataMember * GetDataMember() const
Returns TDataMember pointed by this methodarg.
Method or function calling interface.
Definition TMethodCall.h:37
TFunction * GetMethod()
Returns the TMethod describing the method to be executed.
Each ROOT class (see TClass) has a linked list of methods.
Definition TMethod.h:38
virtual const char * GetCommentString()
Returns a comment string from the class declaration.
Definition TMethod.cxx:107
TClass * GetClass() const
Definition TMethod.h:55
EMenuItemKind IsMenuItem() const
Definition TMethod.h:56
TClass * IsA() const override
Definition TMethod.h:68
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
An array of TObjects.
Definition TObjArray.h:31
Monitors objects for deletion and reflects the deletion by reverting the internal pointer to zero.
Definition TObjectSpy.h:30
TObject * GetObject() const
Definition TObjectSpy.h:45
void SetObject(TObject *obj, Bool_t fixMustCleanupBit=kTRUE)
Set obj as the spy target.
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual void Execute(const char *method, const char *params, Int_t *error=nullptr)
Execute method on this object with the given parameter string, e.g.
Definition TObject.cxx:359
virtual TClass * IsA() const
Definition TObject.h:245
Long_t fValue
Data member to which this option belongs.
This class creates a ROOT object browser, constituted by three main tabs.
This class creates a main window with menubar, scrollbars and a drawing area.
Definition TRootCanvas.h:34
This class provides an interface to context sensitive popup menus.
TGPopupMenu * FindHierarchy(const char *commentstring, TString &last_component)
Decodes the Hierarchy="Level0/Level1/Level2/..." statement from the comment field and returns the - i...
virtual void OnlineHelp()
Open the online help matching the actual class/method.
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Handle context menu messages.
void DisplayPopup(Int_t x, Int_t y) override
Display context popup menu for currently selected object.
Bool_t HandleButton(Event_t *event) override
Handle button event in the context menu.
Bool_t HandleMotion(Event_t *event) override
Handle pointer motion event in context menu.
void RecursiveRemove(TObject *obj) override
Close the context menu if the object is deleted in the RecursiveRemove() operation.
void CreateMenu(TObject *object)
Create the context menu depending on the selected object.
TRootContextMenu(const TRootContextMenu &)
void Dialog(TObject *object, TMethod *method) override
Create dialog object with OK and Cancel buttons.
TList * fTrash
list of objects to be deleted before refilling menu
TRootDialog * fDialog
dialog prompting for command line arguments
void DrawEntry(TGMenuEntry *entry) override
Draw context menu entry.
Bool_t HandleCrossing(Event_t *event) override
Handle pointer crossing event in context menu.
void AddEntrySorted(TGPopupMenu *current, const char *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, Bool_t sorted=kTRUE)
Add a entry to current menu with alphabetical ordering.
~TRootContextMenu() override
Delete a context menu.
A TRootDialog is used to prompt for the arguments of an object's member function.
Definition TRootDialog.h:21
virtual void Add(const char *argname, const char *value, const char *type)
Add a label and text input field.
virtual const char * GetParameters()
Get parameter string (called by contextmenu after OK or Apply has been selected).
virtual void Popup()
Popup dialog.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:457
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2244
const char * Data() const
Definition TString.h:376
@ kIgnoreCase
Definition TString.h:277
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:931
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2264
TString & Remove(Ssiz_t pos)
Definition TString.h:685
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
This class defines toggling facility for both - object's method or variables.
Definition TToggle.h:47
virtual void SetOnValue(Long_t lon)
Definition TToggle.h:78
TMethodCall * GetSetter() const
Definition TToggle.h:87
virtual void SetToggledObject(TObject *obj, TMethod *anymethod)
Initializes it to toggle an object's datamember using this object's method.
Definition TToggle.cxx:135
virtual void SetState(Bool_t state)
Sets the value of toggle to fOnValue or fOffValue according to passed argument.
Definition TToggle.cxx:80
virtual Bool_t GetState()
Returns the state of Toggle according to its current value and fOnValue, returns true if they match.
Definition TToggle.cxx:69
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual Int_t GetCanvasID() const =0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fX
Definition GuiTypes.h:178
TMarker m
Definition textangle.C:8
static byte * ptr2
Definition gifdecode.c:17