test
CMS 3D CMS Logo

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