Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
13void poptest1(int a = 5, int b = 56);
14void poptest2(int a, int b, TObject *c);
15void poptest2bis(TObject *c);
16int poptest3();
17void poptest4(char *ch);
18
19void customContextMenu()
20{
21 TH1F *h;
22 TH1F *h2;
24 TList *l;
25
26 // Create test histograms
27 h = new TH1F("h", "Schtroumpf", 100, -4, 4);
28 h->FillRandom("gaus");
29 h->Draw();
30
31 h2 = new TH1F("h2", "h2", 1000, -4, 4);
32 h2->FillRandom("gaus", 30000);
33
34 // Retrieve menu list from TClass
35 TClass *cl = h->IsA();
36 l = cl->GetMenuList();
37
38 // Add some items to the popup menus
39 n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction, cl, "Test object, draw a second h", "Draw", h2,
40 "Option_t*");
41 l->AddFirst(n);
43 l->AddFirst(n);
44
45 n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction, cl, "test no 4", "poptest4", 0, "const char*");
46 l->AddFirst(n);
47 n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction, cl, "test no 3", "poptest3", 0, "");
48 l->AddFirst(n);
49 n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction, cl, "test no 2 bis", "poptest2bis", 0, "TObject*", 2);
50 l->AddFirst(n);
51 n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction, cl, "test no 2", "poptest2", 0, "int,int,TObject*", 2);
52 l->AddFirst(n);
53 n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction, cl, "test no 1", "poptest1", 0, "int,int");
54 l->AddFirst(n);
55}
56
57void poptest1(int a, int b)
58{
59 printf("poptest1 %d %d\n", a, b);
60}
61
62void poptest2(int a, int b, TObject *c)
63{
64 // Remark: the object c will not be asked for since it is the selected object
65 printf("poptest2 %d %d\n", a, b);
66 printf("histo : %lx\n", (Long_t)c);
67 printf("title of the histogram : %s\n", ((TH1F *)c)->GetTitle());
68}
69
70void poptest2bis(TObject *c)
71{
72 // Remark: the object c will not be asked for since it is the selected object
73 printf("poptest2bis\n");
74 printf("histo : %lx\n", (Long_t)c);
75 printf("title of the histogram : %s\n", ((TH1F *)c)->GetTitle());
76}
77
78int poptest3()
79{
80 printf("poptest3\n");
81 return 12;
82}
83
84void poptest4(const char *ch)
85{
86 printf("poptest4 %s\n", ch);
87}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
long Long_t
Definition RtypesCore.h:54
Describes one element of the context menu associated to a class The menu item may describe.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
TList * GetMenuList() const
Return the list of menu items associated with the class.
Definition TClass.cxx:4410
TClass * IsA() const override
Definition TClass.h:619
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:41
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4