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 TNamed *tn = nullptr;
37
38 if (strcmp(m->GetClass()->GetName(), "TH1") == 0) {
39 if (strcmp(m->GetName(), "SetHighlight") == 0) continue;
40 if (strcmp(m->GetName(), "DrawPanel") == 0) is_editor = kTRUE;
41 } else if (strcmp(m->GetClass()->GetName(), "TGraph") == 0) {
42 if (strcmp(m->GetName(), "SetHighlight") == 0) continue;
43 if (strcmp(m->GetName(), "DrawPanel") == 0) is_editor = kTRUE;
44 } else if (strcmp(m->GetClass()->GetName(), "TAttFill") == 0) {
45 if (strcmp(m->GetName(), "SetFillAttributes") == 0) is_editor = kTRUE;
46 } else if (strcmp(m->GetClass()->GetName(), "TAttLine") == 0) {
47 if (strcmp(m->GetName(), "SetLineAttributes") == 0) is_editor = kTRUE;
48 } else if (strcmp(m->GetClass()->GetName(), "TAttMarker") == 0) {
49 if (strcmp(m->GetName(), "SetMarkerAttributes") == 0) is_editor = kTRUE;
50 } else if (strcmp(m->GetClass()->GetName(), "TAttText") == 0) {
51 if (strcmp(m->GetName(), "SetTextAttributes") == 0) is_editor = kTRUE;
52 } else if (strcmp(m->GetClass()->GetName(), "TNamed") == 0) {
54 if (offset >= 0)
55 tn = (TNamed *) ((char *) obj + offset);
56 }
57
58 if (is_editor) {
59 if (!has_editor) {
60 AddMenuItem("Editor", "Attributes editor", "Show:Editor", last_class ? last_class : m->GetClass());
61 has_editor = kTRUE;
62 }
63 continue;
64 }
65
66 last_class = m->GetClass();
67
68 if (m->IsMenuItem() == kMenuToggle) {
69 TString getter;
70 if (m->Getter() && strlen(m->Getter()) > 0) {
71 getter = m->Getter();
72 } else if (strncmp(m->GetName(), "Set", 3) == 0) {
73 getter = TString(m->GetName())(3, strlen(m->GetName()) - 3);
74 if (cl->GetMethodAllAny(TString("Has") + getter))
75 getter = TString("Has") + getter;
76 else if (cl->GetMethodAllAny(TString("Get") + getter))
77 getter = TString("Get") + getter;
78 else if (cl->GetMethodAllAny(TString("Is") + getter))
79 getter = TString("Is") + getter;
80 else
81 getter = "";
82 }
83
84 if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
85 // execute getter method to get current state of toggle item
86
87 TMethodCall *call = new TMethodCall(cl, getter, "");
88
89 if (call->ReturnType() == TMethodCall::kLong) {
90 Longptr_t l(0);
91 call->Execute(obj, l);
92
93 AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, TString::Format("%s(%s)", m->GetName(), (l != 0) ? "0" : "1").Data(), m->GetClass());
94
95 } else {
96 // Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
97 }
98
99 delete call;
100 }
101 } else {
102 TList *args = m->GetListOfMethodArgs();
103
104 if (!args || (args->GetSize() == 0)) {
105 AddMenuItem(m->GetName(), m->GetTitle(), TString::Format("%s()", m->GetName()).Data(), m->GetClass());
106 } else {
108 item->SetExec(TString::Format("%s()", m->GetName()).Data());
109 if (m->GetClass()) item->SetClassName(m->GetClass()->GetName());
110
111 TIter args_iter(args);
112 TMethodArg *arg = nullptr;
113
114 while ((arg = dynamic_cast<TMethodArg *>(args_iter())) != nullptr) {
115 const char *dflt = "";
116 if (tn && (strcmp(m->GetName(), "SetTitle") == 0))
117 dflt = tn->GetTitle();
118 else if (tn && (strcmp(m->GetName(), "SetName") == 0))
119 dflt = tn->GetName();
120 else
121 dflt = arg->GetDefault();
122 if (!dflt)
123 dflt = "";
124 item->GetArgs().emplace_back(arg->GetName(), arg->GetTitle(), arg->GetFullTypeName(), dflt);
125 }
126
127 Add(item);
128 }
129 }
130 }
131
132 delete lst;
133}
long Longptr_t
Definition RtypesCore.h:82
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
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
@ kMenuToggle
Definition TMethod.h:34
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.
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 *=nullptr) override
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
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()
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
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:421
const char * Data() const
Definition TString.h:380
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:2356
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 belongs 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)
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4