GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TWebMenuItem.cxx
Go to the documentation of this file.
1 // Author: Sergey Linev, GSI 29/06/2017
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2018, 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 
19 void TWebMenuItems::PopulateObjectMenu(void *obj, TClass *cl)
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  Long_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 }
void SetExec(const std::string &exec)
Definition: TWebMenuItem.h:41
void PopulateObjectMenu(void *obj, TClass *cl)
int l
Definition: f_mbs_status.c:31
std::vector< std::unique_ptr< TWebMenuItem > > fItems
list of items in the menu
Definition: TWebMenuItem.h:116
void Add(TWebMenuItem *item)
Definition: TWebMenuItem.h:121
std::vector< TWebMenuArgument > & GetArgs()
Definition: TWebMenuItem.h:107
void AddMenuItem(const std::string &name, const std::string &title, const std::string &exec, TClass *cl=nullptr)
Definition: TWebMenuItem.h:123
void AddChkMenuItem(const std::string &name, const std::string &title, bool checked, const std::string &toggle, TClass *cl=nullptr)
Definition: TWebMenuItem.h:131
void SetClassName(const std::string &clname)
Definition: TWebMenuItem.h:44