Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TWebMenuItem.cxx
Go to the documentation of this file.
1// Author: Sergey Linev, GSI 29/06/2017
2
3/*************************************************************************
4 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "TWebMenuItem.h"
12
13#include "TClass.h"
14#include "TList.h"
15#include "TMethod.h"
16#include "TMethodArg.h"
17#include "TMethodCall.h"
18
20{
21 fItems.clear();
22
23 TList *lst = new TList;
24 cl->GetMenuItems(lst);
25
26 TIter iter(lst);
27 TMethod *m = nullptr;
28
29 Bool_t has_editor = kFALSE;
30
31 TClass *last_class = nullptr;
32
33 while ((m = (TMethod *)iter()) != nullptr) {
34
35 Bool_t is_editor = kFALSE;
36
37 if (strcmp(m->GetClass()->GetName(), "TH1") == 0) {
38 if (strcmp(m->GetName(), "SetHighlight") == 0) continue;
39 if (strcmp(m->GetName(), "DrawPanel") == 0) is_editor = kTRUE;
40 } else if (strcmp(m->GetClass()->GetName(), "TGraph") == 0) {
41 if (strcmp(m->GetName(), "SetHighlight") == 0) continue;
42 if (strcmp(m->GetName(), "DrawPanel") == 0) is_editor = kTRUE;
43 } else if (strcmp(m->GetClass()->GetName(), "TAttFill") == 0) {
44 if (strcmp(m->GetName(), "SetFillAttributes") == 0) is_editor = kTRUE;
45 } else if (strcmp(m->GetClass()->GetName(), "TAttLine") == 0) {
46 if (strcmp(m->GetName(), "SetLineAttributes") == 0) is_editor = kTRUE;
47 } else if (strcmp(m->GetClass()->GetName(), "TAttMarker") == 0) {
48 if (strcmp(m->GetName(), "SetMarkerAttributes") == 0) is_editor = kTRUE;
49 } else if (strcmp(m->GetClass()->GetName(), "TAttText") == 0) {
50 if (strcmp(m->GetName(), "SetTextAttributes") == 0) is_editor = kTRUE;
51 }
52
53 if (is_editor) {
54 if (!has_editor) {
55 AddMenuItem("Editor", "Attributes editor", "Show:Editor", last_class ? last_class : m->GetClass());
56 has_editor = kTRUE;
57 }
58 continue;
59 }
60
61 last_class = m->GetClass();
62
63 if (m->IsMenuItem() == kMenuToggle) {
64 TString getter;
65 if (m->Getter() && strlen(m->Getter()) > 0) {
66 getter = m->Getter();
67 } else if (strncmp(m->GetName(), "Set", 3) == 0) {
68 getter = TString(m->GetName())(3, strlen(m->GetName()) - 3);
69 if (cl->GetMethodAllAny(TString("Has") + getter))
70 getter = TString("Has") + getter;
71 else if (cl->GetMethodAllAny(TString("Get") + getter))
72 getter = TString("Get") + getter;
73 else if (cl->GetMethodAllAny(TString("Is") + getter))
74 getter = TString("Is") + getter;
75 else
76 getter = "";
77 }
78
79 if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
80 // execute getter method to get current state of toggle item
81
82 TMethodCall *call = new TMethodCall(cl, getter, "");
83
84 if (call->ReturnType() == TMethodCall::kLong) {
85 Longptr_t l(0);
86 call->Execute(obj, l);
87
88 AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, Form("%s(%s)", m->GetName(), (l != 0) ? "0" : "1"), m->GetClass());
89
90 } else {
91 // Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
92 }
93
94 delete call;
95 }
96 } else {
97 TList *args = m->GetListOfMethodArgs();
98
99 if (!args || (args->GetSize() == 0)) {
100 AddMenuItem(m->GetName(), m->GetTitle(), Form("%s()", m->GetName()), m->GetClass());
101 } else {
102 TWebArgsMenuItem *item = new TWebArgsMenuItem(m->GetName(), m->GetTitle());
103 item->SetExec(Form("%s()", m->GetName()));
104 if (m->GetClass()) item->SetClassName(m->GetClass()->GetName());
105
106 TIter args_iter(args);
107 TMethodArg *arg = nullptr;
108
109 while ((arg = dynamic_cast<TMethodArg *>(args_iter())) != nullptr) {
110 const char *dflt = arg->GetDefault();
111 if (!dflt) dflt = "";
112 item->GetArgs().emplace_back(arg->GetName(), arg->GetTitle(), arg->GetFullTypeName(), dflt);
113 }
114
115 Add(item);
116 }
117 }
118 }
119
120 delete lst;
121}
long Longptr_t
Definition RtypesCore.h:82
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
@ kMenuToggle
Definition TMethod.h:34
char * Form(const char *fmt,...)
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
void GetMenuItems(TList *listitems)
Returns list of methods accessible by context menu.
Definition TClass.cxx:3860
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4370
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2966
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
A doubly linked list.
Definition TList.h:38
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
const char * GetDefault() const
Get default value of method argument.
Method or function calling interface.
Definition TMethodCall.h:37
EReturnType ReturnType()
Returns the return type of the method.
static const EReturnType kLong
Definition TMethodCall.h:43
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition TMethodCall.h:64
Each ROOT class (see TClass) has a linked list of methods.
Definition TMethod.h:38
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
std::vector< TWebMenuArgument > & GetArgs()
void SetExec(const std::string &exec)
Set execution string with all required arguments, which will be executed when menu item is selected
void SetClassName(const std::string &clname)
Set class name, to which method belons to
void PopulateObjectMenu(void *obj, TClass *cl)
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, TClass *cl=nullptr)
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, TClass *cl=nullptr)
std::vector< std::unique_ptr< TWebMenuItem > > fItems
list of items in the menu
void Add(TWebMenuItem *item)
auto * m
Definition textangle.C:8
auto * l
Definition textangle.C:4