Logo ROOT  
Reference Guide
customContextMenu.C File Reference

Detailed Description

Example showing how to add a function to the class context menu

#include "TH1.h"
#include "TClassMenuItem.h"
#include "TList.h"
void poptest1(int a=5, int b = 56);
void poptest2(int a, int b, TObject* c);
void poptest2bis(TObject* c);
int poptest3();
void poptest4(char* ch);
void customContextMenu()
{
TH1F *h;
TH1F *h2;
TList *l;
// Create test histograms
h = new TH1F("h","Schtroumpf",100,-4,4);
h->FillRandom("gaus");
h->Draw();
h2 = new TH1F("h2","h2",1000,-4,4);
h2->FillRandom("gaus",30000);
// Retrieve menu list from TClass
TClass *cl = h->IsA();
l = cl->GetMenuList();
// Add some items to the popup menus
"Test object, draw a second h","Draw",h2,"Option_t*");
l->AddFirst(n);
l->AddFirst(n);
"test no 4","poptest4",0,"const char*");
l->AddFirst(n);
"test no 3","poptest3",0,"");
l->AddFirst(n);
"test no 2 bis","poptest2bis",0,"TObject*",2);
l->AddFirst(n);
"test no 2","poptest2",0,"int,int,TObject*",2);
l->AddFirst(n);
"test no 1","poptest1",0,"int,int");
l->AddFirst(n);
}
void poptest1(int a, int b)
{
printf("poptest1 %d %d\n",a,b);
}
void poptest2(int a, int b, TObject *c)
{
// Remark: the object c will not be asked for since it is the selected object
printf("poptest2 %d %d\n",a,b);
printf("histo : %lx\n",(Long_t)c);
printf("title of the histogram : %s\n",((TH1F*)c)->GetTitle());
}
void poptest2bis(TObject *c)
{
// Remark: the object c will not be asked for since it is the selected object
printf("poptest2bis\n");
printf("histo : %lx\n",(Long_t)c);
printf("title of the histogram : %s\n",((TH1F*)c)->GetTitle());
}
int poptest3()
{
printf("poptest3\n");
return 12;
}
void poptest4(const char *ch)
{
printf("poptest4 %s\n",ch);
}
Author
Ilka Antcheva

Definition in file customContextMenu.C.

c
#define c(i)
Definition: RSha256.hxx:119
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
TClassMenuItem.h
b
#define b(i)
Definition: RSha256.hxx:118
h
#define h(i)
Definition: RSha256.hxx:124
TClassMenuItem
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:4251
TH1::FillRandom
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3444
TClass
Definition: TClass.h:80
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TObject
Definition: TObject.h:37
TH1.h
TList
Definition: TList.h:44