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