Logo ROOT  
Reference Guide
customContextMenu.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// Example showing how to add a function to the class context menu
4 ///
5 /// \macro_code
6 ///
7 /// \author Ilka Antcheva
8 
9 #include "TH1.h"
10 #include "TClassMenuItem.h"
11 #include "TList.h"
12 
13 void poptest1(int a=5, int b = 56);
14 void poptest2(int a, int b, TObject* c);
15 void poptest2bis(TObject* c);
16 int poptest3();
17 void poptest4(char* ch);
18 
19 
20 void customContextMenu()
21 {
22  TH1F *h;
23  TH1F *h2;
25  TList *l;
26 
27  // Create test histograms
28  h = new TH1F("h","Schtroumpf",100,-4,4);
29  h->FillRandom("gaus");
30  h->Draw();
31 
32  h2 = new TH1F("h2","h2",1000,-4,4);
33  h2->FillRandom("gaus",30000);
34 
35  // Retrieve menu list from TClass
36  TClass *cl = h->IsA();
37  l = cl->GetMenuList();
38 
39  // Add some items to the popup menus
41  "Test object, draw a second h","Draw",h2,"Option_t*");
42  l->AddFirst(n);
44  l->AddFirst(n);
45 
47  "test no 4","poptest4",0,"const char*");
48  l->AddFirst(n);
50  "test no 3","poptest3",0,"");
51  l->AddFirst(n);
53  "test no 2 bis","poptest2bis",0,"TObject*",2);
54  l->AddFirst(n);
56  "test no 2","poptest2",0,"int,int,TObject*",2);
57  l->AddFirst(n);
59  "test no 1","poptest1",0,"int,int");
60  l->AddFirst(n);
61 }
62 
63 void poptest1(int a, int b)
64 {
65  printf("poptest1 %d %d\n",a,b);
66 }
67 
68 void poptest2(int a, int b, TObject *c)
69 {
70  // Remark: the object c will not be asked for since it is the selected object
71  printf("poptest2 %d %d\n",a,b);
72  printf("histo : %lx\n",(Long_t)c);
73  printf("title of the histogram : %s\n",((TH1F*)c)->GetTitle());
74 }
75 
76 void poptest2bis(TObject *c)
77 {
78  // Remark: the object c will not be asked for since it is the selected object
79  printf("poptest2bis\n");
80  printf("histo : %lx\n",(Long_t)c);
81  printf("title of the histogram : %s\n",((TH1F*)c)->GetTitle());
82 }
83 
84 int poptest3()
85 {
86  printf("poptest3\n");
87  return 12;
88 }
89 
90 void poptest4(const char *ch)
91 {
92  printf("poptest4 %s\n",ch);
93 }
c
#define c(i)
Definition: RSha256.hxx:101
l
auto * l
Definition: textangle.C:4
n
const Int_t n
Definition: legend1.C:16
TClassMenuItem::kPopupSeparator
@ kPopupSeparator
Definition: TClassMenuItem.h:35
TList.h
TH1::FillRandom
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3525
TClassMenuItem.h
b
#define b(i)
Definition: RSha256.hxx:100
h
#define h(i)
Definition: RSha256.hxx:106
TClassMenuItem
Describes one element of the context menu associated to a class The menu item may describe.
Definition: TClassMenuItem.h:31
a
auto * a
Definition: textangle.C:12
TClassMenuItem::kPopupUserFunction
@ kPopupUserFunction
Definition: TClassMenuItem.h:35
Long_t
long Long_t
Definition: RtypesCore.h:54
TClass::GetMenuList
TList * GetMenuList() const
Return the list of menu items associated with the class.
Definition: TClass.cxx:4325
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TH1.h
TList
A doubly linked list.
Definition: TList.h:44