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 TNamed *tn = nullptr;
51
52 if (match(m_cl, "TH1")) {
53 if (match(m, "SetHighlight")) continue;
54 if (match(m, "DrawPanel")) is_editor = true;
55 } else if (match(m_cl, "TGraph")) {
56 if (match(m, "SetHighlight")) continue;
57 if (match(m, "DrawPanel")) is_editor = true;
58 } else if (match(m_cl, "TAttFill")) {
59 if (match(m, "SetFillAttributes")) is_editor = true;
60 } else if (match(m_cl, "TAttLine")) {
61 if (match(m, "SetLineAttributes")) is_editor = true;
62 } else if (match(m_cl, "TAttMarker")) {
63 if (match(m, "SetMarkerAttributes")) is_editor = true;
64 } else if (match(m_cl, "TAttText")) {
65 if (match(m, "SetTextAttributes")) is_editor = true;
66 } else if (match(m_cl, "TNamed")) {
68 if (offset >= 0)
69 tn = (TNamed *) ((char *) obj + offset);
70 }
71
72 if (is_editor) {
73 if (!has_editor) {
74 AddMenuItem("Editor", "Attributes editor", "Show:Editor", last_class ? last_class : m_cl);
75 has_editor = true;
76 }
77 continue;
78 }
79
80 last_class = m_cl;
81
82 if (m->IsMenuItem() == kMenuToggle) {
83 TString getter;
84 if (m->Getter() && strlen(m->Getter()) > 0) {
85 getter = m->Getter();
86 } else if (strncmp(m->GetName(), "Set", 3) == 0) {
87 getter = TString(m->GetName())(3, strlen(m->GetName()) - 3);
88 if (cl->GetMethodAllAny(TString("Has") + getter))
89 getter = TString("Has") + getter;
90 else if (cl->GetMethodAllAny(TString("Get") + getter))
91 getter = TString("Get") + getter;
92 else if (cl->GetMethodAllAny(TString("Is") + getter))
93 getter = TString("Is") + getter;
94 else
95 getter = "";
96 }
97
98 if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
99 // execute getter method to get current state of toggle item
100
101 auto call = std::make_unique<TMethodCall>(cl, getter, "");
102
103 if (call->ReturnType() == TMethodCall::kLong) {
104 Longptr_t l = 0;
105 call->Execute(obj, l);
106
107 AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, TString::Format("%s(%s)", m->GetName(), (l != 0) ? "0" : "1").Data(), m_cl);
108
109 } else {
110 // Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
111 }
112 }
113 } else {
114 TList *args = m->GetListOfMethodArgs();
115
116 if (!args || (args->GetSize() == 0)) {
117 AddMenuItem(m->GetName(), m->GetTitle(), TString::Format("%s()", m->GetName()).Data(), m_cl);
118 } else {
119 auto item = std::make_unique<Detail::RArgsMenuItem>(m->GetName(), m->GetTitle());
120 item->SetExec(TString::Format("%s()", m->GetName()).Data());
121 item->SetClassName(m_cl->GetName());
122
123 TIter args_iter(args);
124 TMethodArg *arg = nullptr;
125
126 while ((arg = dynamic_cast<TMethodArg *>(args_iter())) != nullptr) {
127 Detail::RMenuArgument menu_arg(arg->GetName(), arg->GetTitle(), arg->GetFullTypeName());
128 if (tn && match(m, "SetTitle"))
129 menu_arg.SetDefault(tn->GetTitle());
130 else if (tn && match(m, "SetName"))
131 menu_arg.SetDefault(tn->GetName());
132 else if (arg->GetDefault())
133 menu_arg.SetDefault(arg->GetDefault());
134 item->AddArg(menu_arg);
135 }
136
137 Add(std::move(item));
138 }
139 }
140 }
141}
142
143//////////////////////////////////////////////////////////
144/// fill menu items for the drawable
145
146std::unique_ptr<RDrawableReply> RDrawableMenuRequest::Process()
147{
148 auto drawable = GetContext().GetDrawable();
149 if (!drawable) return nullptr;
150
151 auto items = std::make_unique<RMenuItems>(menureqid, menukind);
152
153 drawable->PopulateMenu(*items);
154
155 return items;
156}
long Longptr_t
Definition RtypesCore.h:82
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
char name[80]
Definition TGX11.cxx:110
@ kMenuToggle
Definition TMethod.h:34
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
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)
~RMenuItems() override
destructor - pin vtable
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:81
Int_t GetBaseClassOffset(const TClass *toBase, void *address=nullptr, bool isDerivedObject=true)
Definition TClass.cxx:2791
void GetMenuItems(TList *listitems)
Returns list of methods accessible by context menu.
Definition TClass.cxx:3874
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4384
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
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual void Execute(const char *method, const char *params, Int_t *error=nullptr)
Execute method on this object with the given parameter string, e.g.
Definition TObject.cxx:359
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:483
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
const char * Data() const
Definition TString.h:376
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4