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