Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RMenuItems.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#include "ROOT/RMenuItems.hxx"
10
11#include "ROOT/RDrawable.hxx"
12
13#include "TROOT.h"
14#include "TString.h"
15#include "TClass.h"
16#include "TList.h"
17#include "TMethod.h"
18#include "TMethodArg.h"
19#include "TMethodCall.h"
20
21using namespace ROOT::Experimental;
22
23//////////////////////////////////////////////////////////
24/// destructor - pin vtable
25
26RMenuItems::~RMenuItems() = default;
27
28//////////////////////////////////////////////////////////
29/// Fill menu for provided object, using *MENU* as indicator in method comments
30
32{
33 fItems.clear();
34
35 TList lst;
36 cl->GetMenuItems(&lst);
37
38 TIter iter(&lst);
39 TMethod *m = nullptr;
40
41 TClass *last_class = nullptr;
42 bool has_editor = false;
43
44 auto match = [](const TObject *v, const char *name) { return !strcmp(v->GetName(), name); };
45
46 while ((m = (TMethod *)iter()) != nullptr) {
47
48 TClass *m_cl = m->GetClass();
49 bool is_editor = false;
50
51 if (match(m_cl, "TH1")) {
52 if (match(m, "SetHighlight")) continue;
53 if (match(m, "DrawPanel")) is_editor = true;
54 } else if (match(m_cl, "TGraph")) {
55 if (match(m, "SetHighlight")) continue;
56 if (match(m, "DrawPanel")) is_editor = true;
57 } else if (match(m_cl, "TAttFill")) {
58 if (match(m, "SetFillAttributes")) is_editor = true;
59 } else if (match(m_cl, "TAttLine")) {
60 if (match(m, "SetLineAttributes")) is_editor = true;
61 } else if (match(m_cl, "TAttMarker")) {
62 if (match(m, "SetMarkerAttributes")) is_editor = true;
63 } else if (match(m_cl, "TAttText")) {
64 if (match(m, "SetTextAttributes")) is_editor = true;
65 }
66
67 if (is_editor) {
68 if (!has_editor) {
69 AddMenuItem("Editor", "Attributes editor", "Show:Editor", last_class ? last_class : m_cl);
70 has_editor = true;
71 }
72 continue;
73 }
74
75 last_class = m_cl;
76
77 if (m->IsMenuItem() == kMenuToggle) {
78 TString getter;
79 if (m->Getter() && strlen(m->Getter()) > 0) {
80 getter = m->Getter();
81 } else if (strncmp(m->GetName(), "Set", 3) == 0) {
82 getter = TString(m->GetName())(3, strlen(m->GetName()) - 3);
83 if (cl->GetMethodAllAny(TString("Has") + getter))
84 getter = TString("Has") + getter;
85 else if (cl->GetMethodAllAny(TString("Get") + getter))
86 getter = TString("Get") + getter;
87 else if (cl->GetMethodAllAny(TString("Is") + getter))
88 getter = TString("Is") + getter;
89 else
90 getter = "";
91 }
92
93 if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
94 // execute getter method to get current state of toggle item
95
96 auto call = std::make_unique<TMethodCall>(cl, getter, "");
97
98 if (call->ReturnType() == TMethodCall::kLong) {
99 Longptr_t l(0);
100 call->Execute(obj, l);
101
102 AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, Form("%s(%s)", m->GetName(), (l != 0) ? "0" : "1"), m_cl);
103
104 } else {
105 // Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
106 }
107 }
108 } else {
109 TList *args = m->GetListOfMethodArgs();
110
111 if (!args || (args->GetSize() == 0)) {
112 AddMenuItem(m->GetName(), m->GetTitle(), Form("%s()", m->GetName()), m_cl);
113 } else {
114 auto item = std::make_unique<Detail::RArgsMenuItem>(m->GetName(), m->GetTitle());
115 item->SetExec(Form("%s()", m->GetName()));
116 item->SetClassName(m_cl->GetName());
117
118 TIter args_iter(args);
119 TMethodArg *arg = nullptr;
120
121 while ((arg = dynamic_cast<TMethodArg *>(args_iter())) != nullptr) {
122 Detail::RMenuArgument menu_arg(arg->GetName(), arg->GetTitle(), arg->GetFullTypeName());
123 if (arg->GetDefault()) menu_arg.SetDefault(arg->GetDefault());
124 item->AddArg(menu_arg);
125 }
126
127 Add(std::move(item));
128 }
129 }
130 }
131}
132
133//////////////////////////////////////////////////////////
134/// fill menu items for the drawable
135
136std::unique_ptr<RDrawableReply> RDrawableMenuRequest::Process()
137{
138 auto drawable = GetContext().GetDrawable();
139 if (!drawable) return nullptr;
140
141 auto items = std::make_unique<RMenuItems>(menureqid, menukind);
142
143 drawable->PopulateMenu(*items);
144
145 return items;
146}
long Longptr_t
Definition RtypesCore.h:82
char name[80]
Definition TGX11.cxx:110
@ kMenuToggle
Definition TMethod.h:34
char * Form(const char *fmt,...)
Argument description for menu item which should invoke class method.
void SetDefault(const std::string &dflt)
std::unique_ptr< RDrawableReply > Process() override
fill menu items for the drawable
const RDrawable::RDisplayContext & GetContext() const
virtual ~RMenuItems()
destructor - pin vtable
std::vector< std::unique_ptr< Detail::RMenuItem > > fItems
list of items in the menu
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, const TClass *cl=nullptr)
void Add(std::unique_ptr< Detail::RMenuItem > &&item)
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, const TClass *cl=nullptr)
void PopulateObjectMenu(void *obj, TClass *cl)
Fill menu for provided object, using MENU as indicator in method comments.
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.
static const EReturnType kLong
Definition TMethodCall.h:43
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
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
auto * m
Definition textangle.C:8
auto * l
Definition textangle.C:4