1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include "AliMUONPainterInterfaceHelper.h"
20 ///\class AliMUONPainterInterfaceHelper
22 /// Helper class to work with TGButtonGroup
24 /// This class only works if the buttons in the TGButtonGroup have contiguous
25 /// ids, and if those ids start at ButtonStartingId().
26 /// Not bullet-proof, I admit, but this is the only way I've found with
27 /// the current TGButtonGroup implementation which does not allow to loop
28 /// easily on all buttons.
30 // Author Laurent Aphecetche, Subatech
32 #include "AliMUONPainterEnv.h"
33 #include "AliMUONPainterHelper.h"
35 #include <Riostream.h>
37 #include <TGButtonGroup.h>
40 #include <TObjArray.h>
41 #include <TObjString.h>
47 ClassImp(AliMUONPainterInterfaceHelper)
50 //_____________________________________________________________________________
51 AliMUONPainterInterfaceHelper::AliMUONPainterInterfaceHelper() : TObject()
56 //_____________________________________________________________________________
57 AliMUONPainterInterfaceHelper::~AliMUONPainterInterfaceHelper()
62 //_____________________________________________________________________________
64 AliMUONPainterInterfaceHelper::AddRadioButton(TGButtonGroup& bg,
69 /// Add a radio button to a group
70 Int_t n = bg.GetCount();
72 TGButton* button = new TGRadioButton(&bg,
74 n+ButtonStartingId());
75 button->SetUserData(userData);
76 button->SetOn(select,kFALSE);
79 //_____________________________________________________________________________
81 AliMUONPainterInterfaceHelper::AddCheckButton(TGButtonGroup& bg,
86 /// Add a check button to a group
87 Int_t n = bg.GetCount();
89 TGButton* button = new TGCheckButton(&bg,
91 n+ButtonStartingId());
92 button->SetUserData(userData);
93 button->SetOn(select,kFALSE);
96 //_____________________________________________________________________________
98 AliMUONPainterInterfaceHelper::ClearButtons(TGButtonGroup& bg)
100 /// Remove all buttons from group.
101 /// Bear in mind that you're thus disconnecting the group from
102 /// any signals it might have. So you must re-connect them after
103 /// a call to this method, if you want to.
105 while ( bg.GetCount() > 0 )
107 TGTextButton* button = (TGTextButton*)(bg.GetButton(bg.GetCount()));
110 AliFatalClass(Form("Got a null button for bg.Count()=%d",bg.GetCount()));
113 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,16,0)
114 button->DestroyWindow();
120 //_____________________________________________________________________________
122 AliMUONPainterInterfaceHelper::Copy(const TGButtonGroup& src, TGButtonGroup& dest)
124 /// Copy a button group into another one
125 AliDebugClass(1,Form("src=%p (%s) count=%d dest=%p (%s) count=%d",
126 &src,src.GetTitle(),src.GetCount(),
127 &dest,dest.GetTitle(),dest.GetCount()));
129 StdoutToAliDebugClass(1,cout << "---copying:" << endl; Dump(src);
130 cout << "---to:" << endl; Dump(dest));
134 dest.SetTitle(src.GetTitle());
138 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + src.GetCount(); ++i )
140 TGTextButton* tb = static_cast<TGTextButton*>(src.GetButton(i));
141 TGButton* button = new TGRadioButton(&dest,tb->GetTitle(),tb->WidgetId());
142 assert(tb->WidgetId()==i);
143 button->SetUserData(tb->GetUserData());
144 button->SetOn(tb->IsOn(),kFALSE);
149 //_____________________________________________________________________________
151 AliMUONPainterInterfaceHelper::Dump(const TGButtonGroup& bg)
154 cout << Form("ButtonGroup %s %s",bg.GetName(),bg.GetTitle()) << endl;
156 for ( Int_t i = ButtonStartingId(); i < bg.GetCount() + ButtonStartingId(); ++i )
158 TGTextButton* button = static_cast<TGTextButton*>(bg.GetButton(i));
161 cout << Form("i %2d button %s id %d wid %d ON %d",
162 i,button->GetTitle(),button->GetId(),
164 button->IsOn()) << endl;
168 cout << Form("i %2d button = 0x0",i) << endl;
173 //_____________________________________________________________________________
175 AliMUONPainterInterfaceHelper::FindButtonByName(const TGButtonGroup& bg,
178 /// Find a button by name
180 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
182 TGTextButton* button = static_cast<TGTextButton*>(bg.GetButton(i));
185 AliErrorClass(Form("(%s) : Something wrong",name.Data()));
190 if ( name == button->GetTitle() )
199 //_____________________________________________________________________________
201 AliMUONPainterInterfaceHelper::FindButtonByUserData(const TGButtonGroup& bg,
204 /// Find a button by userData
206 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
208 TGButton* button = bg.GetButton(i);
209 if ( button->GetUserData() == userData )
217 //_____________________________________________________________________________
219 AliMUONPainterInterfaceHelper::FindDownButton(const TGButtonGroup& bg)
221 /// Find which button is down (in a radio group)
223 AliDebugClass(1,Form("bg %s",bg.GetTitle()));
225 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
227 TGButton* button = bg.GetButton(i);
228 if ( button->IsOn() )
230 AliDebugClass(1,Form("button %s",button->GetTitle()));
238 //_____________________________________________________________________________
240 AliMUONPainterInterfaceHelper::SetBackgroundColor(const char* resourceBaseName,
243 /// Set the background color of the window
244 TString rs(Form("%s.BackgroundColor",resourceBaseName));
245 TString colorName = AliMUONPainterHelper::Instance()->Env()->String(rs.Data(),"#c0c0c0");
248 Bool_t ok = gClient->GetColorByName(colorName, color);
251 window.SetBackgroundColor(color);
252 AliDebugClass(1,Form("Setting %s color to %s",rs.Data(),colorName.Data()));
256 //_____________________________________________________________________________
258 AliMUONPainterInterfaceHelper::SetState(TGButtonGroup& bg, Bool_t state)
260 /// should not be needed with root > 5.16/00 as there's a TGButtonGroup::SetState
263 #if ROOT_VERSION_CODE > ROOT_VERSION(5,16,0)
266 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
268 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
271 button->SetState(kButtonUp);
275 button->SetState(kButtonDisabled);
281 //_____________________________________________________________________________
283 AliMUONPainterInterfaceHelper::Select(TGButtonGroup& bg,
284 const TString& buttonName,
287 /// Select which button should be on
289 AliDebugClass(1,Form("bg %s buttonName %s",bg.GetTitle(),buttonName.Data()));
291 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
293 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
294 if ( buttonName == button->GetTitle() || buttonName == "*" )
302 button->SetOn(kTRUE);
308 //_____________________________________________________________________________
310 AliMUONPainterInterfaceHelper::Unselect(TGButtonGroup& bg,
311 const TString& buttonName,
314 /// Unselect a given button
316 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
318 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
319 if ( buttonName == button->GetTitle() || buttonName == "*" )
327 button->SetOn(kFALSE);
333 //_____________________________________________________________________________
335 AliMUONPainterInterfaceHelper::RemoveButton(TGButtonGroup& bg,
340 // need to redo it from scratch in order not the leave holes in the
343 TGButtonGroup bgtmp(bg.GetParent(),bg.GetTitle());
345 Int_t id(ButtonStartingId());
347 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
349 TGTextButton* b = static_cast<TGTextButton*>(bg.GetButton(i));
353 TGButton* bc = new TGRadioButton(&bgtmp,b->GetTitle(),id);
355 bc->SetUserData(b->GetUserData());
356 bc->SetOn(b->IsOn());