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// //
14// TRootContextMenu //
15// //
16// This class provides an interface to context sensitive popup menus. //
17// These menus pop up when the user hits the right mouse button, and //
18// are destroyed when the menu pops downs. //
19// The picture below shows a canvas with a pop-up menu. //
20// //
21//Begin_Html <img src="gif/hsumMenu.gif"> End_Html //
22// //
23// The picture below shows a canvas with a pop-up menu and a dialog box.//
24// //
25//Begin_Html <img src="gif/hsumDialog.gif"> End_Html //
26// //
27//////////////////////////////////////////////////////////////////////////
28
29#include "TRootContextMenu.h"
30#include "TROOT.h"
31#include "TGClient.h"
32#include "TEnv.h"
33#include "TList.h"
34#include "TObjArray.h"
35#include "TContextMenu.h"
36#include "TMethod.h"
37#include "TMethodArg.h"
38#include "TMethodCall.h"
39#include "TClass.h"
40#include "TVirtualX.h"
41#include "TCanvas.h"
42#include "TDataMember.h"
43#include "TToggle.h"
44#include "TRootDialog.h"
45#include "TDataType.h"
46#include "TBrowser.h"
47#include "TRootCanvas.h"
48#include "TRootBrowser.h"
49#include "TClassMenuItem.h"
50#include "TObjectSpy.h"
51#include "KeySymbols.h"
52#include "RConfigure.h"
53#include "strlcpy.h"
54#include "snprintf.h"
55
57 kToggleStart = 1000, // first id of toggle menu items
58 kToggleListStart = 2000, // first id of toggle list menu items
59 kUserFunctionStart = 3000 // first id of user added functions/methods, etc...
60};
61
62
64
65////////////////////////////////////////////////////////////////////////////////
66/// Create context menu.
67
69 : TGPopupMenu(gClient->GetDefaultRoot()), TContextMenuImp(c)
70{
71 fDialog = 0;
72 fTrash = new TList;
73
75 gROOT->GetListOfCleanups()->Add(this);
76 // Context menu handles its own messages
77 Associate(this);
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Delete a context menu.
82
84{
85 gROOT->GetListOfCleanups()->Remove(this);
86 delete fDialog;
87 if (fTrash) fTrash->Delete();
88 delete fTrash;
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Display context popup menu for currently selected object.
93
95{
96 if (fClient->IsEditable()) return;
97
98 // delete menu items releated to previous object and reset menu size
100 fCurrent = 0;
101 if (fTrash) fTrash->Delete();
102 fMenuHeight = 6;
103 fMenuWidth = 8;
104
105 // delete previous dialog
106 if (fDialog) {
107 delete fDialog;
108 fDialog = 0;
109 }
110
111 // add menu items to popup menu
113
114 int xx, yy, topx = 0, topy = 0;
115 UInt_t w, h;
116
119 topx, topy, w, h);
120
121 xx = topx + x + 1;
122 yy = topy + y + 1;
123
124#ifdef R__HAS_COCOA
125 //Context menu must be transient for a canvas, otherwise it's possible
126 //to break the z-order (for example, using alt-tab to switch between
127 //different aplications). This hint works ONLY for canvas though
128 //(otherwise selected canvas is null).
129 TGWindow *parent = 0;
131 parent = dynamic_cast<TGWindow *>(pad->GetCanvasImp());
132 else if ((pad = fContextMenu->GetSelectedPad()) && pad->GetCanvasImp())
133 parent = dynamic_cast<TGWindow *>(pad->GetCanvasImp());
134 else if (TBrowser * const browser = fContextMenu->GetBrowser())
135 parent = dynamic_cast<TGWindow *>(browser->GetBrowserImp());
136
137 if (parent)
138 gVirtualX->SetWMTransientHint(GetId(), parent->GetId());
139#endif
140
141 PlaceMenu(xx, yy, kTRUE, kTRUE);
142 // add some space for the right-side '?' (help)
143 fMenuWidth += 5;
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Decodes the Hierarchy="Level0/Level1/Level2/..." statement from the comment field
149/// and returns the - if needed - created sub menu "Level0/Level1"
150/// Returns the last component in last_component.
151
152TGPopupMenu * TRootContextMenu::FindHierarchy(const char *commentstring, TString & last_component)
153{
154 TString cmd(commentstring);
155 TString option;
156 TString hierarchy;
157 TGPopupMenu *currentMenu = 0;
158
159 // search for arguments to the MENU statement
160 // strcpy(cmd,commentstring);
161 Ssiz_t opt_ptr;
162 if ((opt_ptr=cmd.Index("*MENU={")) != kNPOS ||
163 (opt_ptr=cmd.Index("*SUBMENU={"))!= kNPOS ||
164 (opt_ptr=cmd.Index("*TOGGLE={")) != kNPOS ) {
165
166 Ssiz_t start = cmd.Index("{",opt_ptr) + 1;
167 Ssiz_t end = cmd.Index("}",start);
168 option = cmd(start,end - start);
169
170 // Look for Hierarchy token
171 TObjArray * array = option.Tokenize(";");
172 TIter iter(array);
173 TObject *obj;
174 while((obj = iter())) {
175 TString token(obj->GetName());
176 if (token.Index("Hierarchy=\"") != kNPOS) {
177 Ssiz_t tstart = token.Index("\"") + 1;
178 Ssiz_t tend = token.Index("\"",tstart+1);
179 if (tend == kNPOS) continue;
180 hierarchy = token(tstart,tend - tstart);
181 }
182 }
183 delete array;
184 }
185
186 // Build Hierarchy
187 currentMenu = this;
188 TObjArray * array = hierarchy.Tokenize("/");
189 TIter iter(array);
190 TObject *obj = iter();
191 while(obj) {
192 last_component = obj->GetName();
193 obj = iter();
194 if (obj) {
195 TGMenuEntry *ptr;
196 TIter next(currentMenu->GetListOfEntries());
197 // Search for popup with corresponding name
198 while ((ptr = (TGMenuEntry *) next()) &&
199 (ptr->GetType() != kMenuPopup ||
200 last_component.CompareTo(ptr->GetName()))) { }
201 if (ptr)
202 currentMenu = ptr->GetPopup();
203 else {
204 TGPopupMenu *r = new TGPopupMenu(gClient->GetDefaultRoot());
205 // Alphabetical ordering
207 TIter next2(currentMenu->GetListOfEntries());
208 // Search for popup with corresponding name
209 while ((ptr2 = (TGMenuEntry *) next2()) &&
210 (ptr2->GetType() != kMenuPopup ||
211 last_component.CompareTo(ptr2->GetName()) > 0 )) { }
212
213 currentMenu->AddPopup(last_component, r,ptr2);
214 currentMenu = r;
215 fTrash->Add(r);
216 last_component = obj->GetName();
217 }
218 }
219 }
220
221 delete array;
222 return currentMenu;
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Add a entry to current menu with alphabetical ordering.
227
228void TRootContextMenu::AddEntrySorted(TGPopupMenu *currentMenu, const char *s, Int_t id, void *ud,
229 const TGPicture *p , Bool_t sorted)
230{
231 TGMenuEntry *ptr2 = 0;
232 if (sorted) {
233 TIter next(currentMenu->GetListOfEntries());
234 // Search for popup with corresponding name
235 while ((ptr2 = (TGMenuEntry *) next()) &&
236 (ptr2->GetType() != kMenuEntry ||
237 strcmp(ptr2->GetName(), s)<0 )) { }
238 }
239 currentMenu->AddEntry(s,id,ud,p,ptr2);
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Create the context menu depending on the selected object.
244
246{
247 if (!object || fClient->IsEditable()) return;
248
249 int entry = 0, toggle = kToggleStart, togglelist = kToggleListStart;
250 int userfunction = kUserFunctionStart;
251
252 // Add a title
254 AddSeparator();
255
256 // Get list of menu items from the selected object's class
257 TList *menuItemList = object->IsA()->GetMenuList();
258
259 TClassMenuItem *menuItem;
260 TIter nextItem(menuItemList);
261
262 while ((menuItem = (TClassMenuItem*) nextItem())) {
263 switch (menuItem->GetType()) {
265 {
267 if (last && last->GetType() != kMenuSeparator)
268 AddSeparator();
269 break;
270 }
272 {
273 // Standard list of class methods. Rebuild from scratch.
274 // Get linked list of objects menu items (i.e. member functions
275 // with the token *MENU in their comment fields.
276 TList *methodList = new TList;
277 object->IsA()->GetMenuItems(methodList);
278
279 TMethod *method;
280 TClass *classPtr = 0;
281 TIter next(methodList);
282 Bool_t needSep = kFALSE;
283
284 while ((method = (TMethod*) next())) {
285 if (classPtr != method->GetClass()) {
286 needSep = kTRUE;
287 classPtr = method->GetClass();
288 }
289
290 TDataMember *m;
291 EMenuItemKind menuKind = method->IsMenuItem();
292 TGPopupMenu *currentMenu = 0;
293 TString last_component;
294
295 switch (menuKind) {
296 case kMenuDialog:
297 // search for arguments to the MENU statement
298 currentMenu = FindHierarchy(method->GetCommentString(),last_component);
299 if (needSep && currentMenu == this) {
300 AddSeparator();
301 needSep = kFALSE;
302 }
303 AddEntrySorted(currentMenu,last_component.Length() ? last_component.Data() : method->GetName(), entry++, method,0,currentMenu != this);
304 break;
305 case kMenuSubMenu:
306 if ((m = method->FindDataMember())) {
307
308 // search for arguments to the MENU statement
309 currentMenu = FindHierarchy(method->GetCommentString(),last_component);
310
311 if (m->GetterMethod()) {
312 TGPopupMenu *r = new TGPopupMenu(gClient->GetDefaultRoot());
313 if (needSep && currentMenu == this) {
314 AddSeparator();
315 needSep = kFALSE;
316 }
317 if (last_component.Length()) {
318 currentMenu->AddPopup(last_component, r);
319 } else {
320 currentMenu->AddPopup(method->GetName(), r);
321 }
322 fTrash->Add(r);
323 TIter nxt(m->GetOptions());
324 TOptionListItem *it;
325 while ((it = (TOptionListItem*) nxt())) {
326 const char *name = it->fOptName;
327 Long_t val = it->fValue;
328
329 TToggle *t = new TToggle;
330 t->SetToggledObject(object, method);
331 t->SetOnValue(val);
332 fTrash->Add(t);
333
334 r->AddEntry(name, togglelist++, t);
335 if (t->GetState())
336 r->CheckEntry(togglelist-1);
337 }
338 } else {
339 if (needSep && currentMenu == this) {
340 AddSeparator();
341 needSep = kFALSE;
342 }
343 AddEntrySorted(currentMenu,last_component.Length() ? last_component.Data() : method->GetName(), entry++, method,0,currentMenu != this);
344 }
345 }
346 break;
347
348 case kMenuToggle:
349 {
350 TToggle *t = new TToggle;
351 t->SetToggledObject(object, method);
352 t->SetOnValue(1);
353 fTrash->Add(t);
354 // search for arguments to the MENU statement
355 currentMenu = FindHierarchy(method->GetCommentString(),last_component);
356 if (needSep && currentMenu == this) {
357 AddSeparator();
358 needSep = kFALSE;
359 }
360 AddEntrySorted(currentMenu,last_component.Length() ? last_component.Data() : method->GetName(), toggle++, t,0,currentMenu != this);
361 if (t->GetState()) currentMenu->CheckEntry(toggle-1);
362 }
363 break;
364
365 default:
366 break;
367 }
368 }
369 delete methodList;
370 }
371 break;
373 {
374 const char* menuItemTitle = menuItem->GetTitle();
375 if (menuItem->IsToggle()) {
376 TMethod* method =
377 object->IsA()->GetMethodWithPrototype(menuItem->GetFunctionName(),menuItem->GetArgs());
378 if (method) {
379 TToggle *t = new TToggle;
380 t->SetToggledObject(object, method);
381 t->SetOnValue(1);
382 fTrash->Add(t);
383
384 if (strlen(menuItemTitle)==0) menuItemTitle = method->GetName();
385 AddEntry(menuItemTitle, toggle++, t);
386 if (t->GetState()) CheckEntry(toggle-1);
387 }
388 } else {
389 if (strlen(menuItemTitle)==0) menuItemTitle = menuItem->GetFunctionName();
390 AddEntry(menuItemTitle,userfunction++,menuItem);
391 }
392 }
393 break;
394 default:
395 break;
396 }
397 }
398}
399
400////////////////////////////////////////////////////////////////////////////////
401/// Create dialog object with OK and Cancel buttons. This dialog
402/// prompts for the arguments of "method".
403
405{
406 Dialog(object,(TFunction*)method);
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Create dialog object with OK and Cancel buttons. This dialog
411/// prompts for the arguments of "function".
412/// function may be a global function or a method
413
415{
416 Int_t selfobjpos;
417
418 if (!function) return;
419
420 // Position, if it exists, of the argument that correspond to the object itself
423 else selfobjpos = -1;
424
425 const TGWindow *w;
428 // Embedded canvas has no canvasimp that is a TGFrame
429 // coverity[returned_null]
430 // coverity[dereference]
431 if (c->GetCanvasImp()->IsA()->InheritsFrom(TGFrame::Class())) {
432 w = fClient->GetWindowById(gVirtualX->GetWindowID(c->GetCanvasID()));
433 if (!w) w = (TRootCanvas *) c->GetCanvasImp();
434 } else {
435 w = gClient->GetDefaultRoot();
436 }
437 } else if (fContextMenu->GetBrowser()) {
439 w = (TRootBrowser *) b->GetBrowserImp();
440 } else {
441 w = gClient->GetDefaultRoot();
442 }
443 fDialog = new TRootDialog(this, w, fContextMenu->CreateDialogTitle(object, function));
444
445 // iterate through all arguments and create apropriate input-data objects:
446 // inputlines, option menus...
447 TMethodArg *argument = 0;
448
449 TIter next(function->GetListOfMethodArgs());
450 Int_t argpos = 0;
451
452 while ((argument = (TMethodArg *) next())) {
453 // Do not input argument for self object
454 if (selfobjpos != argpos) {
455 const char *argname = fContextMenu->CreateArgumentTitle(argument);
456 const char *type = argument->GetTypeName();
457 TDataType *datatype = gROOT->GetType(type);
458 const char *charstar = "char*";
459 char basictype[32];
460
461 if (datatype) {
462 strlcpy(basictype, datatype->GetTypeName(), 32);
463 } else {
465 if (strncmp(type, "enum", 4) && (cl && !(cl->Property() & kIsEnum)))
466 Warning("Dialog", "data type is not basic type, assuming (int)");
467 strlcpy(basictype, "int", 32);
468 }
469
470 if (strchr(argname, '*')) {
471 strlcat(basictype, "*",32);
472 if (!strncmp(type, "char", 4) || !strncmp(type, "Option_t", 8))
473 type = charstar;
474 else if (strstr(argname, "[default:")) {
475 // skip arguments that are pointers (but not char *)
476 // and have a default value
477 argpos++;
478 continue;
479 }
480 }
481
482 TDataMember *m = argument->GetDataMember();
483 if (m && object && m->GetterMethod(object->IsA())) {
484
485 // Get the current value and form it as a text:
486
487 char val[256];
488
489 if (!strncmp(basictype, "char*", 5)) {
490 char *tdefval;
491 m->GetterMethod()->Execute(object, "", &tdefval);
492 strlcpy(val, tdefval, sizeof(val));
493 } else if (!strncmp(basictype, "float", 5) ||
494 !strncmp(basictype, "double", 6)) {
495 Double_t ddefval;
496 m->GetterMethod()->Execute(object, "", ddefval);
497 snprintf(val,256, "%g", ddefval);
498 } else if (!strncmp(basictype, "char", 4) ||
499 !strncmp(basictype, "bool", 4) ||
500 !strncmp(basictype, "int", 3) ||
501 !strncmp(basictype, "long", 4) ||
502 !strncmp(basictype, "short", 5)) {
503 Long_t ldefval;
504 m->GetterMethod()->Execute(object, "", ldefval);
505 snprintf(val,256, "%li", ldefval);
506 }
507
508 // Find out whether we have options ...
509
510 TList *opt;
511 // coverity[returned_pointer]: keep for later use
512 if ((opt = m->GetOptions())) {
513 Warning("Dialog", "option menu not yet implemented");
514#if 0
515 TMotifOptionMenu *o= new TMotifOptionMenu(argname);
516 TIter nextopt(opt);
517 TOptionListItem *it = 0;
518 while ((it = (TOptionListItem*) nextopt())) {
519 char *name = it->fOptName;
520 char *label = it->fOptLabel;
521 Long_t value = it->fValue;
522 if (value != -9999) {
523 char val[256];
524 snprintf(val,256, "%li", value);
525 o->AddItem(name, val);
526 }else
527 o->AddItem(name, label);
528 }
529 o->SetData(val);
530 fDialog->Add(o);
531#endif
532 } else {
533 // we haven't got options - textfield ...
534 fDialog->Add(argname, val, type);
535 }
536 } else { // if m not found ...
537
538 char val[256] = "";
539 const char *tval = argument->GetDefault();
540 if (tval && strlen(tval)) {
541 // Remove leading and trailing quotes
542 strlcpy(val, tval + (tval[0] == '"' ? 1 : 0), sizeof(val));
543 if (val[strlen(val)-1] == '"')
544 val[strlen(val)-1]= 0;
545 }
546 fDialog->Add(argname, val, type);
547 }
548 }
549 argpos++;
550 }
551
552 fDialog->Popup();
553}
554
555////////////////////////////////////////////////////////////////////////////////
556/// Draw context menu entry.
557
559{
560 int ty, offset;
561 static int max_ascent = 0, max_descent = 0;
562
564 // draw the ? (help) in the right side when highlighting a menu entry
565 if (entry->GetType() == kMenuEntry && (entry->GetStatus() & kMenuActiveMask)) {
566 if (max_ascent == 0) {
567 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
568 }
569 offset = (entry->GetEh() - (max_ascent + max_descent)) / 2;
570 ty = entry->GetEy() + max_ascent + offset - 1;
571 TGHotString s("&?");
572 s.Draw(fId, fSelGC, fMenuWidth-12, ty);
573 }
574}
575
576////////////////////////////////////////////////////////////////////////////////
577/// Handle button event in the context menu.
578
580{
581 int id;
582 void *ud = 0;
583
584 if ((event->fType == kButtonRelease) && (event->fX >= (Int_t)(fMenuWidth-15)) &&
585 (event->fX <= (Int_t)fMenuWidth)) {
586 id = EndMenu(ud);
587 if (fHasGrab) gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab
588 if (ud) {
589 // retrieve the highlighted function
590 TFunction *function = 0;
591 if (id < kToggleStart) {
592 TMethod *m = (TMethod *)ud;
593 function = (TFunction *)m;
594 } else if (id >= kToggleStart && id < kUserFunctionStart) {
595 TToggle *t = (TToggle *)ud;
596 TMethodCall *mc = (TMethodCall *)t->GetSetter();
597 function = (TFunction *)mc->GetMethod();
598 } else {
599 TClassMenuItem *mi = (TClassMenuItem *)ud;
600 function = gROOT->GetGlobalFunctionWithPrototype(mi->GetFunctionName());
601 }
602 if (function)
603 fContextMenu->SetMethod(function);
604 }
605 OnlineHelp();
606 return kTRUE;
607 }
608 return TGPopupMenu::HandleButton(event);
609}
610
611////////////////////////////////////////////////////////////////////////////////
612/// Handle pointer crossing event in context menu.
613
615{
616 if (event->fType == kLeaveNotify) {
617 // just to reset the mouse pointer...
618 HandleMotion(event);
619 }
620 return TGPopupMenu::HandleCrossing(event);
621}
622
623////////////////////////////////////////////////////////////////////////////////
624/// Handle pointer motion event in context menu.
625
627{
628 static int toggle = 0;
629 static Cursor_t handCur = kNone, rightCur = kNone;
631
632 if (handCur == kNone)
633 handCur = gVirtualX->CreateCursor(kHand);
634 if (rightCur == kNone)
635 rightCur = gVirtualX->CreateCursor(kArrowRight);
636
637 if (event->fType == kLeaveNotify) {
638 gVirtualX->ChangeActivePointerGrab(fId, mask, rightCur);
639 toggle = 0;
640 return kTRUE;
641 }
642 // change the cursot to a small hand when over the ? (help)
643 if ((event->fX >= (Int_t)(fMenuWidth-15)) && (event->fX <= (Int_t)fMenuWidth) &&
644 fCurrent && (fCurrent->GetType() == kMenuEntry)) {
645 if (toggle == 0) {
646 gVirtualX->ChangeActivePointerGrab(fId, mask, handCur);
647 toggle = 1;
648 }
649 }
650 else {
651 if (toggle == 1) {
652 gVirtualX->ChangeActivePointerGrab(fId, mask, rightCur);
653 toggle = 0;
654 }
655 }
656 return TGPopupMenu::HandleMotion(event);
657}
658
659////////////////////////////////////////////////////////////////////////////////
660/// Open the online help matching the actual class/method.
661
663{
664 TString clname;
665 TString cmd;
666 TString url = gEnv->GetValue("Browser.StartUrl", "http://root.cern.ch/root/html/");
667 if (url.EndsWith(".html", TString::kIgnoreCase)) {
668 if (url.Last('/') != kNPOS)
669 url.Remove(url.Last('/'));
670 }
671 if (!url.EndsWith("/")) {
672 url += '/';
673 }
675 if (obj) {
676 clname = obj->ClassName();
679 TMethod *method = obj->IsA()->GetMethodAllAny(smeth.Data());
680 if (method) clname = method->GetClass()->GetName();
681 url += clname;
682 url += ".html";
683 url += "#";
684 url += clname;
685 url += ":";
686 url += smeth.Data();
687 }
688 else {
689 url += clname;
690 url += ".html";
691 }
692 if (fDialog) delete fDialog;
693 fDialog = 0;
694 cmd = TString::Format("new TGHtmlBrowser(\"%s\", 0, 900, 300);", url.Data());
695 gROOT->ProcessLine(cmd.Data());
696 }
697}
698
699////////////////////////////////////////////////////////////////////////////////
700/// Handle context menu messages.
701
703{
704 TObjectSpy savedPad;
705 if (GetContextMenu()->GetSelectedPad()) {
706 savedPad.SetObject(gPad);
708 }
709
710 switch (GET_MSG(msg)) {
711
712 case kC_COMMAND:
713
714 switch (GET_SUBMSG(msg)) {
715
716 case kCM_MENU:
717
718 if (parm1 < kToggleStart) {
719 TMethod *m = (TMethod *) parm2;
721 } else if (parm1 >= kToggleStart && parm1 < kToggleListStart) {
722 TToggle *t = (TToggle *) parm2;
724 } else if (parm1 >= kToggleListStart && parm1<kUserFunctionStart) {
725 TToggle *t = (TToggle *) parm2;
726 if (t->GetState() == 0)
727 t->SetState(1);
728 } else {
729 TClassMenuItem *mi = (TClassMenuItem*)parm2;
730 GetContextMenu()->Action(mi);
731 }
732 break;
733
734 case kCM_BUTTON:
735 if (parm1 == 1) {
736 const char *args = fDialog->GetParameters();
737 GetContextMenu()->Execute((char *)args);
738 delete fDialog;
739 fDialog = 0;
740 }
741 if (parm1 == 2) {
742 const char *args = fDialog->GetParameters();
743 GetContextMenu()->Execute((char *)args);
744 }
745 if (parm1 == 3) {
746 delete fDialog;
747 fDialog = 0;
748 }
749 if (parm1 == 4) {
750 OnlineHelp();
751 }
752 break;
753
754 default:
755 break;
756 }
757 break;
758
759 case kC_TEXTENTRY:
760
761 switch (GET_SUBMSG(msg)) {
762
763 case kTE_ENTER:
764 {
765 const char *args = fDialog->GetParameters();
766 GetContextMenu()->Execute((char *)args);
767 delete fDialog;
768 fDialog = 0;
769 }
770 break;
771
772 default:
773 break;
774 }
775 break;
776
777 default:
778 break;
779 }
780
781 if (savedPad.GetObject()) gPad = (TVirtualPad*) savedPad.GetObject();
782
783 return kTRUE;
784}
785
786////////////////////////////////////////////////////////////////////////////////
787/// Close the context menu if the object is deleted in the
788/// RecursiveRemove() operation.
789
791{
792 void *ud;
793 if (obj == fContextMenu->GetSelectedCanvas())
795 if (obj == fContextMenu->GetSelectedPad())
797 if (obj == fContextMenu->GetSelectedObject()) {
798 // if the object being deleted is the one selected,
799 // ungrab the mouse pointer and terminate (close) the menu
801 if (fHasGrab)
802 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
803 EndMenu(ud);
804 }
805}
806
@ kButtonRelease
Definition GuiTypes.h:60
@ kLeaveNotify
Definition GuiTypes.h:61
Handle_t Cursor_t
Cursor handle.
Definition GuiTypes.h:34
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
const Mask_t kPointerMotionMask
Definition GuiTypes.h:163
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
@ kArrowRight
Definition GuiTypes.h:375
@ kHand
Definition GuiTypes.h:374
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
const Ssiz_t kNPOS
Definition RtypesCore.h:115
const Bool_t kFALSE
Definition RtypesCore.h:92
long Long_t
Definition RtypesCore.h:54
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
@ kIsEnum
Definition TDictionary.h:68
R__EXTERN TEnv * gEnv
Definition TEnv.h:171
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:231
#define gClient
Definition TGClient.h:166
@ kMenuActiveMask
Definition TGMenu.h:35
@ kMenuEntry
Definition TGMenu.h:49
@ kMenuSeparator
Definition TGMenu.h:47
@ kMenuPopup
Definition TGMenu.h:50
XFontStruct * id
Definition TGX11.cxx:109
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
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:338
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
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
virtual const char * GetTitle() const
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:80
Long_t Property() const
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6063
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:2957
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.
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.
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
TMethodCall * GetterMethod(TClass *cl=0)
Return a TMethodCall method responsible for getting the value of data member.
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:98
TGWindow * GetWindowById(Window_t sw) const
Find a TGWindow via its handle. If window is not found return 0.
Definition TGClient.cxx:593
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:324
virtual UInt_t GetDefaultWidth() const
Definition TGFrame.h:214
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:215
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:590
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
TGPopupMenu * GetPopup() const
Definition TGMenu.h:100
Int_t GetEy() const
Definition TGMenu.h:104
virtual Int_t GetStatus() const
Definition TGMenu.h:98
EMenuEntryType GetType() const
Definition TGMenu.h:99
UInt_t GetEh() const
Definition TGMenu.h:106
const char * GetName() const
Returns name of object.
Definition TGMenu.h:96
TGClient * fClient
Definition TGObject.h:37
Handle_t GetId() const
Definition TGObject.h:47
Handle_t fId
Definition TGObject.h:36
TList * fEntryList
Definition TGMenu.h:130
virtual void AddLabel(TGHotString *s, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu label to the menu.
Definition TGMenu.cxx:1094
TGMenuEntry * fCurrent
Definition TGMenu.h:131
virtual Bool_t HandleMotion(Event_t *event)
Handle pointer motion event in popup menu.
Definition TGMenu.cxx:1393
UInt_t fMenuHeight
Definition TGMenu.h:137
virtual Bool_t HandleButton(Event_t *event)
Handle button event in the popup menu.
Definition TGMenu.cxx:1337
GContext_t fSelGC
Definition TGMenu.h:140
virtual void AddPopup(TGHotString *s, TGPopupMenu *popup, TGMenuEntry *before=nullptr, const TGPicture *p=nullptr)
Add a (cascading) popup menu to a popup menu.
Definition TGMenu.cxx:1151
virtual void CheckEntry(Int_t id)
Check a menu entry (i.e. add a check mark in front of it).
Definition TGMenu.cxx:1781
virtual void DrawEntry(TGMenuEntry *entry)
Draw popup menu entry.
Definition TGMenu.cxx:1505
virtual Bool_t HandleCrossing(Event_t *event)
Handle pointer crossing event in popup menu.
Definition TGMenu.cxx:1366
FontStruct_t fFontStruct
Definition TGMenu.h:142
virtual void Associate(const TGWindow *w)
Definition TGMenu.h:219
virtual Int_t EndMenu(void *&userData)
Close menu and return ID of selected menu item.
Definition TGMenu.cxx:1288
virtual void AddSeparator(TGMenuEntry *before=nullptr)
Add a menu separator to the menu.
Definition TGMenu.cxx:1059
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu entry.
Definition TGMenu.cxx:989
UInt_t fMenuWidth
Definition TGMenu.h:136
virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
Popup a popup menu.
Definition TGMenu.cxx:1240
const TList * GetListOfEntries() const
Definition TGMenu.h:213
Bool_t fHasGrab
Definition TGMenu.h:133
A doubly linked list.
Definition TList.h:44
virtual void Add(TObject *obj)
Definition TList.h:87
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:693
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
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.
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition TMethodCall.h:64
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
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
An array of TObjects.
Definition TObjArray.h:37
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:37
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:130
Long_t fValue
Data member to which this option belongs.
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(Long_t msg, Long_t parm1, Long_t parm2)
Handle context menu messages.
virtual Bool_t HandleButton(Event_t *event)
Handle button event in the context menu.
virtual void Dialog(TObject *object, TMethod *method)
Create dialog object with OK and Cancel buttons.
virtual Bool_t HandleMotion(Event_t *event)
Handle pointer motion event in context menu.
virtual void RecursiveRemove(TObject *obj)
Close the context menu if the object is deleted in the RecursiveRemove() operation.
virtual void DisplayPopup(Int_t x, Int_t y)
Display context popup menu for currently selected object.
void CreateMenu(TObject *object)
Create the context menu depending on the selected object.
TRootContextMenu(const TRootContextMenu &)
TRootDialog * fDialog
virtual ~TRootContextMenu()
Delete a 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.
virtual void DrawEntry(TGMenuEntry *entry)
Draw context menu entry.
virtual Bool_t HandleCrossing(Event_t *event)
Handle pointer crossing event in context menu.
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:136
Ssiz_t Length() const
Definition TString.h:410
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:438
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2197
const char * Data() const
Definition TString.h:369
@ kIgnoreCase
Definition TString.h:268
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:912
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition TString.cxx:2217
TString & Remove(Ssiz_t pos)
Definition TString.h:673
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:2331
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:639
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
auto * m
Definition textangle.C:8
static byte * ptr2
Definition gifdecode.c:17