CMS 3D CMS Logo

CSGAction.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : CSGAction
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu May 29 20:58:11 CDT 2008
11 //
12 
13 // system include files
14 #include <TString.h>
15 #include <TGResourcePool.h>
16 #include <TQObject.h>
17 #include <KeySymbols.h>
18 #include <TGMenu.h>
19 #include <TVirtualX.h>
20 
21 // user include files
26 
27 //
28 // constants, enums and typedefs
29 //
30 
31 //
32 // static data member definitions
33 //
34 
35 //
36 // constructors and destructor
37 //
38 CSGAction::CSGAction(CSGActionSupervisor* supervisor, const char* name) : m_connector(nullptr) {
39  m_enabled = true;
40  m_globalEnabled = true;
41  m_supervisor = supervisor;
42  m_name = name;
43  m_toolTip = "";
44  m_menu = nullptr;
45  m_toolBar = nullptr;
46  m_tools = nullptr;
50  m_keycode = 0;
51  m_modcode = 0;
52  m_windowID = -1;
53 }
54 // CSGAction::CSGAction(const CSGAction& rhs)
55 // {
56 // // do actual copying here;
57 // }
58 
60  delete m_connector;
61  //Don't delete GUI parts since they are owned by their GUI parent
62 }
63 
64 //
65 // assignment operators
66 //
67 // const CSGAction& CSGAction::operator=(const CSGAction& rhs)
68 // {
69 // //An exception safe implementation is
70 // CSGAction temp(rhs);
71 // swap(rhs);
72 //
73 // return *this;
74 // }
75 
76 //
77 // member functions
78 //
79 const std::string& CSGAction::getName() const { return m_name; }
80 
81 const std::string& CSGAction::getToolTip() const { return m_toolTip; }
82 
83 TString CSGAction::getSCCombo() const { return m_scCombo; }
84 
86  // Does not update menu yet
87  m_name = name;
88 
89  for (std::vector<TGButton*>::iterator it = m_buttons.begin(), itEnd = m_buttons.end(); it != itEnd; ++it) {
90  TGTextButton* tb = dynamic_cast<TGTextButton*>(*it);
91  if (tb) {
92  (tb)->SetText(name.c_str());
93  gClient->NeedRedraw(tb);
94  }
95  }
96 }
97 
99  if (m_menu) {
100  m_menu->GetEntry(m_entry)->GetLabel()->SetString(label.c_str());
101  }
102 }
103 
105  m_toolTip = tip;
106  for (std::vector<TGButton*>::iterator it = m_buttons.begin(), itEnd = m_buttons.end(); it != itEnd; ++it) {
107  (*it)->SetToolTipText(tip.c_str(), m_supervisor->getToolTipDelay());
108  }
109  if (m_tools != nullptr)
110  m_tools->fTipText = tip.c_str();
111 }
112 
114  TGCompositeFrame* p, TGLayoutHints* l, Int_t id, GContext_t norm, FontStruct_t font, UInt_t option) {
115  TGTextButton* textButton = new TGTextButton(p, m_name.c_str(), id, norm, font, option);
116  if (!m_toolTip.empty())
117  textButton->SetToolTipText(m_toolTip.c_str(), m_supervisor->getToolTipDelay());
118  p->AddFrame(textButton, l);
119  TQObject::Connect(textButton, "Clicked()", "CSGAction", this, "activate()");
120  m_buttons.push_back(textButton);
121  if (!isEnabled()) {
122  textButton->SetEnabled(kFALSE);
123  }
124 }
125 
127  TGCompositeFrame* p, TGLayoutHints* l, Bool_t state, Int_t id, GContext_t norm, FontStruct_t font) {
128  TGCheckButton* checkButton = new TGCheckButton(p, m_name.c_str(), id, norm, font);
129  if (!m_toolTip.empty())
130  checkButton->SetToolTipText(m_toolTip.c_str(), m_supervisor->getToolTipDelay());
131  p->AddFrame(checkButton, l);
132 
133  if (state)
134  checkButton->SetState(kButtonDown, false);
135  TQObject::Connect(checkButton, "Clicked()", "CSGAction", this, "activate()");
136  m_buttons.push_back(checkButton);
137  if (!isEnabled()) {
138  checkButton->SetEnabled(kFALSE);
139  }
140 }
141 
143  TGCompositeFrame* p, const TGPicture* pic, TGLayoutHints* l, Int_t id, GContext_t norm, UInt_t option) {
144  TGPictureButton* picButton = new TGPictureButton(p, pic, id, norm, option);
145  if (!m_toolTip.empty())
146  picButton->SetToolTipText(m_toolTip.c_str(), m_supervisor->getToolTipDelay());
147  p->AddFrame(picButton, l);
148  TQObject::Connect(picButton, "Clicked()", "CSGAction", this, "activate()");
149  m_buttons.push_back(picButton);
150  if (!isEnabled()) {
151  picButton->SetEnabled(kFALSE);
152  }
153 }
154 
156  const TGPicture* upPic,
157  const TGPicture* downPic,
158  const TGPicture* disabledPic,
159  TGLayoutHints* l,
160  Int_t id,
161  GContext_t norm,
162  UInt_t option) {
163  FWCustomIconsButton* picButton = new FWCustomIconsButton(p, upPic, downPic, disabledPic, nullptr, id, norm, option);
164  if (!m_toolTip.empty())
165  picButton->SetToolTipText(m_toolTip.c_str(), m_supervisor->getToolTipDelay());
166  p->AddFrame(picButton, l);
167  TQObject::Connect(picButton, "Clicked()", "CSGAction", this, "activate()");
168  m_buttons.push_back(picButton);
169  if (!isEnabled()) {
170  picButton->SetEnabled(kFALSE);
171  }
172  return picButton;
173 }
174 
175 void CSGAction::createShortcut(UInt_t key, const char* mod, int windowID) {
176  Int_t keycode = gVirtualX->KeysymToKeycode((int)key);
177  m_windowID = windowID;
178  Int_t modcode;
179  TString scText;
180  if (strcmp(mod, "CTRL") == 0) {
181  modcode = kKeyControlMask;
182  scText = "<ctrl> ";
183  } else if (strcmp(mod, "CTRL+SHIFT") == 0) {
184  modcode = kKeyControlMask | kKeyShiftMask;
185  scText = "<ctrl> <shift> ";
186  } else {
187  // Default to ALT for now
188  modcode = kKeyMod1Mask;
189  scText = "<alt> ";
190  }
191  scText += keycodeToString(keycode);
192  m_scCombo = scText;
193 
194  gVirtualX->GrabKey(m_windowID, keycode, modcode, kTRUE);
195  gVirtualX->GrabKey(m_windowID, keycode, modcode | kKeyMod2Mask, kTRUE);
196  gVirtualX->GrabKey(m_windowID, keycode, modcode | kKeyLockMask, kTRUE);
197  gVirtualX->GrabKey(m_windowID, keycode, modcode | kKeyMod2Mask | kKeyLockMask, kTRUE);
198 
199  m_keycode = keycode;
200  m_modcode = modcode;
201  if (m_menu != nullptr)
202  addSCToMenu();
203 }
204 
205 void CSGAction::createMenuEntry(TGPopupMenu* menu) {
206  m_menu = menu;
207  if (!(menu->HasConnection("Activated(Int_t)")))
208  TQObject::Connect(menu, "Activated(Int_t)", "CSGConnector", m_connector, "handleMenu(Int_t)");
209  menu->AddEntry(m_name.c_str(), m_entry);
210  if (m_keycode != 0)
211  addSCToMenu();
212  if (!isEnabled()) {
213  m_menu->DisableEntry(m_entry);
214  }
215 }
216 
218  Bool_t widthChanged = resizeMenuEntry();
219  if (widthChanged)
221 }
222 
224  FontStruct_t font = gClient->GetResourcePool()->GetMenuHiliteFont()->GetFontStruct();
225  Bool_t widthChanged = kTRUE;
226  UInt_t width = m_menu->GetWidth();
227  TString realName(m_name);
228  if (realName.Contains("->")) {
229  // Should make function to do this and store in member data...
230  while (!(realName.BeginsWith("->")) && realName.Length() > 0) {
231  realName.Replace(0, 1, nullptr, 0);
232  }
233  realName.Replace(0, 2, nullptr, 0);
234  }
235  TString scText = m_scCombo;
236  while (gVirtualX->TextWidth(font, realName.Data(), realName.Length()) +
237  gVirtualX->TextWidth(font, scText.Data(), scText.Length()) + 53 <
238  (Int_t)width) {
239  widthChanged = kFALSE;
240  realName += " ";
241  }
242  realName += "\t";
243  realName += scText;
244  TIter next(m_menu->GetListOfEntries());
245  TGMenuEntry* current;
246  while (nullptr != (current = (TGMenuEntry*)next())) {
247  if (current == m_menu->GetEntry(m_entry)) {
248  break;
249  }
250  }
251  current = (TGMenuEntry*)next();
252  m_menu->DeleteEntry(m_entry);
253  m_menu->AddEntry(realName, m_entry, nullptr, nullptr, current);
254  return widthChanged;
255 }
256 
257 TGPopupMenu* CSGAction::getMenu() const { return m_menu; }
258 
259 int CSGAction::getMenuEntry() const { return m_entry; }
260 
261 Int_t CSGAction::getKeycode() const { return m_keycode; }
262 
263 Int_t CSGAction::getModcode() const { return m_modcode; }
264 
265 ToolBarData_t* CSGAction::getToolBarData() const { return m_tools; }
266 
267 TGToolBar* CSGAction::getToolBar() const { return m_toolBar; }
268 
270  m_enabled = true;
271  enableImp();
272 }
273 
275  m_enabled = false;
276  disableImp();
277 }
278 
280  m_globalEnabled = true;
281  enableImp();
282 }
283 
285  m_globalEnabled = false;
286  disableImp();
287 }
288 
289 Bool_t CSGAction::isEnabled() const { return m_enabled && m_globalEnabled; }
290 
292  if (isEnabled()) {
293  if (m_menu != nullptr)
294  m_menu->EnableEntry(m_entry);
295  for (std::vector<TGButton*>::iterator it = m_buttons.begin(), itEnd = m_buttons.end(); it != itEnd; ++it) {
296  (*it)->SetEnabled(kTRUE);
297  }
298 
299  if (m_toolBar != nullptr)
300  m_toolBar->GetButton(m_entry)->SetEnabled(kTRUE);
301  if (m_keycode != 0) {
302  gVirtualX->GrabKey(m_windowID, m_keycode, m_modcode, kTRUE);
303  gVirtualX->GrabKey(m_windowID, m_keycode, m_modcode | kKeyMod2Mask, kTRUE);
304  gVirtualX->GrabKey(m_windowID, m_keycode, m_modcode | kKeyLockMask, kTRUE);
305  gVirtualX->GrabKey(m_windowID, m_keycode, m_modcode | kKeyMod2Mask | kKeyLockMask, kTRUE);
306  }
307  }
308 }
309 
311  if (!isEnabled()) {
312  if (m_menu != nullptr)
313  m_menu->DisableEntry(m_entry);
314  for (std::vector<TGButton*>::iterator it = m_buttons.begin(), itEnd = m_buttons.end(); it != itEnd; ++it) {
315  (*it)->SetEnabled(kFALSE);
316  }
317  if (m_toolBar != nullptr)
318  m_toolBar->GetButton(m_entry)->SetEnabled(kFALSE);
319  if (m_keycode != 0) {
320  gVirtualX->GrabKey(m_windowID, m_keycode, m_modcode, kFALSE);
321  gVirtualX->GrabKey(m_windowID, m_keycode, m_modcode | kKeyMod2Mask, kFALSE);
322  gVirtualX->GrabKey(m_windowID, m_keycode, m_modcode | kKeyLockMask, kFALSE);
323  gVirtualX->GrabKey(m_windowID, m_keycode, m_modcode | kKeyMod2Mask | kKeyLockMask, kFALSE);
324  }
325  }
326 }
327 
328 //
329 // static member functions
330 //
331 
332 TString CSGAction::keycodeToString(Int_t keycode) {
333  int i;
334  char letter;
335  TString rep;
336  for (i = kKey_a; i < kKey_a + 26; i++) {
337  if (gVirtualX->KeysymToKeycode(i) == keycode) {
338  letter = (char)(i - kKey_a + 'a');
339  rep = TString(letter);
340  return rep;
341  }
342  }
343  for (i = kKey_A; i < kKey_A + 26; i++) {
344  if (gVirtualX->KeysymToKeycode(i) == keycode) {
345  letter = (char)(i - kKey_A + 'a');
346  rep = TString(letter);
347  return rep;
348  }
349  }
350  if (keycode == gVirtualX->KeysymToKeycode(kKey_Left)) {
351  rep = TString("<-");
352  return rep;
353  }
354  if (keycode == gVirtualX->KeysymToKeycode(kKey_Right)) {
355  rep = TString("->");
356  return rep;
357  }
358  if (keycode == gVirtualX->KeysymToKeycode(kKey_Space)) {
359  rep = TString("space");
360  return rep;
361  }
362  rep = TString("");
363  return rep;
364 }
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
mps_fire.i
i
Definition: mps_fire.py:428
CSGAction::enableImp
void enableImp()
Definition: CSGAction.cc:291
FWCustomIconsButton.h
CSGActionSupervisor
Definition: CSGActionSupervisor.h:27
CSGAction::globalDisable
virtual void globalDisable()
Definition: CSGAction.cc:284
CSGAction::createCustomIconsButton
FWCustomIconsButton * createCustomIconsButton(TGCompositeFrame *p, const TGPicture *upPic, const TGPicture *downPic, const TGPicture *disabledPic, TGLayoutHints *l=nullptr, Int_t id=-1, GContext_t norm=TGButton::GetDefaultGC()(), UInt_t option=0)
Definition: CSGAction.cc:155
CSGAction::addSCToMenu
void addSCToMenu()
Definition: CSGAction.cc:217
CSGActionSupervisor::getToolTipDelay
Long_t getToolTipDelay() const
Definition: CSGActionSupervisor.cc:87
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
CSGConnector.h
CSGAction::setToolTip
void setToolTip(const std::string &tip)
Definition: CSGAction.cc:104
CSGAction::getToolBarData
ToolBarData_t * getToolBarData() const
Definition: CSGAction.cc:265
CSGAction::resizeMenuEntry
Bool_t resizeMenuEntry()
Definition: CSGAction.cc:223
CSGAction::createShortcut
void createShortcut(UInt_t key, const char *mod, int windowID)
Definition: CSGAction.cc:175
CSGAction::m_keycode
Int_t m_keycode
Definition: CSGAction.h:115
CSGAction::disable
void disable()
Definition: CSGAction.cc:274
CSGAction::m_enabled
Bool_t m_enabled
Definition: CSGAction.h:122
fileinputsource_cfi.option
option
Definition: fileinputsource_cfi.py:87
CSGAction::getName
const std::string & getName() const
Definition: CSGAction.cc:79
CSGAction::getModcode
Int_t getModcode() const
Definition: CSGAction.cc:263
CSGAction::createCheckButton
void createCheckButton(TGCompositeFrame *p, TGLayoutHints *l=nullptr, Bool_t state=true, Int_t id=-1, GContext_t norm=TGButton::GetDefaultGC()(), FontStruct_t font=TGTextButton::GetDefaultFontStruct())
Definition: CSGAction.cc:126
CSGAction::m_entry
int m_entry
Definition: CSGAction.h:118
CSGAction::m_scCombo
TString m_scCombo
Definition: CSGAction.h:113
CSGAction::~CSGAction
virtual ~CSGAction()
Definition: CSGAction.cc:59
CSGAction::setMenuLabel
void setMenuLabel(const std::string &label)
Definition: CSGAction.cc:98
CSGActionSupervisor.h
CSGAction::setName
void setName(const std::string &name)
Definition: CSGAction.cc:85
CSGAction::getToolTip
const std::string & getToolTip() const
Definition: CSGAction.cc:81
CSGAction::disableImp
void disableImp()
Definition: CSGAction.cc:310
CSGConnector
Definition: CSGConnector.h:30
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
qcdUeDQM_cfi.tip
tip
Definition: qcdUeDQM_cfi.py:23
CSGAction::getToolBar
TGToolBar * getToolBar() const
Definition: CSGAction.cc:267
optionsL1T.menu
menu
Definition: optionsL1T.py:29
FWCustomIconsButton
Definition: FWCustomIconsButton.h:29
CSGAction::m_menu
TGPopupMenu * m_menu
Definition: CSGAction.h:117
CSGAction::m_windowID
int m_windowID
Definition: CSGAction.h:124
CSGAction::m_toolTip
std::string m_toolTip
Definition: CSGAction.h:112
CSGAction.h
CSGAction::getSCCombo
TString getSCCombo() const
Definition: CSGAction.cc:83
CSGAction::m_tools
ToolBarData_t * m_tools
Definition: CSGAction.h:120
cuy.rep
rep
Definition: cuy.py:1190
CSGActionSupervisor::getListOfActions
const std::vector< CSGAction * > & getListOfActions() const
Definition: CSGActionSupervisor.cc:40
CSGAction::createPictureButton
void createPictureButton(TGCompositeFrame *p, const TGPicture *pic, TGLayoutHints *l=nullptr, Int_t id=-1, GContext_t norm=TGButton::GetDefaultGC()(), UInt_t option=kRaisedFrame|kDoubleBorder)
Definition: CSGAction.cc:142
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
CSGAction::keycodeToString
static TString keycodeToString(Int_t keycode)
Definition: CSGAction.cc:332
CSGAction::m_buttons
std::vector< TGButton * > m_buttons
Definition: CSGAction.h:114
CSGActionSupervisor::resizeMenu
void resizeMenu(TGPopupMenu *menu)
Definition: CSGActionSupervisor.cc:78
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
CSGAction::m_supervisor
CSGActionSupervisor * m_supervisor
Definition: CSGAction.h:110
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
CSGAction::isEnabled
virtual Bool_t isEnabled() const
Definition: CSGAction.cc:289
CSGAction::m_modcode
Int_t m_modcode
Definition: CSGAction.h:116
CSGAction::getMenuEntry
int getMenuEntry() const
Definition: CSGAction.cc:259
CSGAction::m_name
std::string m_name
Definition: CSGAction.h:111
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CSGAction::createTextButton
void createTextButton(TGCompositeFrame *p, TGLayoutHints *l=nullptr, Int_t id=-1, GContext_t norm=TGButton::GetDefaultGC()(), FontStruct_t font=TGTextButton::GetDefaultFontStruct(), UInt_t option=kRaisedFrame|kDoubleBorder)
Definition: CSGAction.cc:113
CSGActionSupervisor::addToActionMap
void addToActionMap(CSGAction *action)
Definition: CSGActionSupervisor.cc:38
CSGAction::createMenuEntry
void createMenuEntry(TGPopupMenu *menu)
Definition: CSGAction.cc:205
CSGAction::enable
void enable()
Definition: CSGAction.cc:269
CSGAction::globalEnable
virtual void globalEnable()
Definition: CSGAction.cc:279
crabWrapper.key
key
Definition: crabWrapper.py:19
CSGAction::getKeycode
Int_t getKeycode() const
Definition: CSGAction.cc:261
CSGAction::CSGAction
CSGAction(CSGActionSupervisor *supervisor, const char *name)
Definition: CSGAction.cc:38
CSGAction::m_toolBar
TGToolBar * m_toolBar
Definition: CSGAction.h:119
label
const char * label
Definition: PFTauDecayModeTools.cc:11
CSGAction::m_connector
CSGConnector * m_connector
Definition: CSGAction.h:121
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
CSGAction::m_globalEnabled
Bool_t m_globalEnabled
Definition: CSGAction.h:123
CSGAction::getMenu
TGPopupMenu * getMenu() const
Definition: CSGAction.cc:257