Logo ROOT   6.14/05
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 }
Describes one element of the context menu associated to a class The menu item may describe...
TList * GetMenuList() const
Return the list of menu items associated with the class.
Definition: TClass.cxx:4162
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:285
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: TList.cxx:97
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
A doubly linked list.
Definition: TList.h:44
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3421
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
auto * a
Definition: textangle.C:12
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
#define h(i)
Definition: RSha256.hxx:106
long Long_t
Definition: RtypesCore.h:50
Mother of all ROOT objects.
Definition: TObject.h:37
auto * l
Definition: textangle.C:4
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define c(i)
Definition: RSha256.hxx:101
const Int_t n
Definition: legend1.C:16