ROOT
6.07/01
Reference Guide
ROOT Home Page
Main Page
Tutorials
User's Classes
Namespaces
All Classes
Files
Release Notes
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
tutorials
gui
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
;
24
TClassMenuItem
*
n
;
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
40
n =
new
TClassMenuItem
(
TClassMenuItem::kPopupUserFunction
,cl,
41
"Test object, draw a second h"
,
"Draw"
,h2,
"Option_t*"
);
42
l->
AddFirst
(n);
43
n =
new
TClassMenuItem
(
TClassMenuItem::kPopupSeparator
,cl);
44
l->
AddFirst
(n);
45
46
n =
new
TClassMenuItem
(
TClassMenuItem::kPopupUserFunction
,cl,
47
"test no 4"
,
"poptest4"
,0,
"const char*"
);
48
l->
AddFirst
(n);
49
n =
new
TClassMenuItem
(
TClassMenuItem::kPopupUserFunction
,cl,
50
"test no 3"
,
"poptest3"
,0,
""
);
51
l->
AddFirst
(n);
52
n =
new
TClassMenuItem
(
TClassMenuItem::kPopupUserFunction
,cl,
53
"test no 2 bis"
,
"poptest2bis"
,0,
"TObject*"
,2);
54
l->
AddFirst
(n);
55
n =
new
TClassMenuItem
(
TClassMenuItem::kPopupUserFunction
,cl,
56
"test no 2"
,
"poptest2"
,0,
"int,int,TObject*"
,2);
57
l->
AddFirst
(n);
58
n =
new
TClassMenuItem
(
TClassMenuItem::kPopupUserFunction
,cl,
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
}
TClassMenuItem
Describes one element of the context menu associated to a class The menu item may describe...
Definition:
TClassMenuItem.h:35
TClass::GetMenuList
TList * GetMenuList() const
Return the list of menu items associated with the class.
Definition:
TClass.cxx:3994
TClassMenuItem::kPopupUserFunction
Definition:
TClassMenuItem.h:39
h
TH1 * h
Definition:
legend2.C:5
TList::AddFirst
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition:
TList.cxx:93
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition:
TH1.h:570
h2
TH2D * h2
Definition:
fit2dHist.C:45
TList.h
TClassMenuItem::kPopupSeparator
Definition:
TClassMenuItem.h:39
TList
A doubly linked list.
Definition:
TList.h:47
TClassMenuItem.h
TH1::FillRandom
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition:
TH1.cxx:3330
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition:
TH1.cxx:2878
l
TLine * l
Definition:
textangle.C:4
TClass
The ROOT global object gROOT contains a list of all defined classes.
Definition:
TClass.h:81
Long_t
long Long_t
Definition:
RtypesCore.h:50
printf
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
TObject
Mother of all ROOT objects.
Definition:
TObject.h:58
TH1.h
n
const Int_t n
Definition:
legend1.C:16