ROOT logo
//How to add a function to the class context menu
//Author: Ilka Antcheva
   
#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;
   TClassMenuItem *n;
   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
   n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                          "Test object, draw a second h","Draw",h2,"Option_t*");
   l->AddFirst(n);
   n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);
   l->AddFirst(n);

   n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                          "test no 4","poptest4",0,"const char*");
   l->AddFirst(n);
   n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                          "test no 3","poptest3",0,"");
   l->AddFirst(n);
   n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                          "test no 2 bis","poptest2bis",0,"TObject*",2);
   l->AddFirst(n);
   n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                          "test no 2","poptest2",0,"int,int,TObject*",2);
   l->AddFirst(n);
   n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                          "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);
}
 customContextMenu.C:1
 customContextMenu.C:2
 customContextMenu.C:3
 customContextMenu.C:4
 customContextMenu.C:5
 customContextMenu.C:6
 customContextMenu.C:7
 customContextMenu.C:8
 customContextMenu.C:9
 customContextMenu.C:10
 customContextMenu.C:11
 customContextMenu.C:12
 customContextMenu.C:13
 customContextMenu.C:14
 customContextMenu.C:15
 customContextMenu.C:16
 customContextMenu.C:17
 customContextMenu.C:18
 customContextMenu.C:19
 customContextMenu.C:20
 customContextMenu.C:21
 customContextMenu.C:22
 customContextMenu.C:23
 customContextMenu.C:24
 customContextMenu.C:25
 customContextMenu.C:26
 customContextMenu.C:27
 customContextMenu.C:28
 customContextMenu.C:29
 customContextMenu.C:30
 customContextMenu.C:31
 customContextMenu.C:32
 customContextMenu.C:33
 customContextMenu.C:34
 customContextMenu.C:35
 customContextMenu.C:36
 customContextMenu.C:37
 customContextMenu.C:38
 customContextMenu.C:39
 customContextMenu.C:40
 customContextMenu.C:41
 customContextMenu.C:42
 customContextMenu.C:43
 customContextMenu.C:44
 customContextMenu.C:45
 customContextMenu.C:46
 customContextMenu.C:47
 customContextMenu.C:48
 customContextMenu.C:49
 customContextMenu.C:50
 customContextMenu.C:51
 customContextMenu.C:52
 customContextMenu.C:53
 customContextMenu.C:54
 customContextMenu.C:55
 customContextMenu.C:56
 customContextMenu.C:57
 customContextMenu.C:58
 customContextMenu.C:59
 customContextMenu.C:60
 customContextMenu.C:61
 customContextMenu.C:62
 customContextMenu.C:63
 customContextMenu.C:64
 customContextMenu.C:65
 customContextMenu.C:66
 customContextMenu.C:67
 customContextMenu.C:68
 customContextMenu.C:69
 customContextMenu.C:70
 customContextMenu.C:71
 customContextMenu.C:72
 customContextMenu.C:73
 customContextMenu.C:74
 customContextMenu.C:75
 customContextMenu.C:76
 customContextMenu.C:77
 customContextMenu.C:78
 customContextMenu.C:79
 customContextMenu.C:80
 customContextMenu.C:81
 customContextMenu.C:82
 customContextMenu.C:83
 customContextMenu.C:84
 customContextMenu.C:85
 customContextMenu.C:86
 customContextMenu.C:87
 customContextMenu.C:88
 customContextMenu.C:89