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>
49 ClassImp(AliMUONPainterInterfaceHelper)
52 //_____________________________________________________________________________
53 AliMUONPainterInterfaceHelper::AliMUONPainterInterfaceHelper() : TObject()
58 //_____________________________________________________________________________
59 AliMUONPainterInterfaceHelper::~AliMUONPainterInterfaceHelper()
64 //_____________________________________________________________________________
66 AliMUONPainterInterfaceHelper::AddRadioButton(TGButtonGroup& bg,
71 /// Add a radio button to a group
72 Int_t n = bg.GetCount();
74 TGButton* button = new TGRadioButton(&bg,
76 n+ButtonStartingId());
77 button->SetUserData(userData);
78 button->SetOn(select,kFALSE);
81 //_____________________________________________________________________________
83 AliMUONPainterInterfaceHelper::AddCheckButton(TGButtonGroup& bg,
88 /// Add a check button to a group
89 Int_t n = bg.GetCount();
91 TGButton* button = new TGCheckButton(&bg,
93 n+ButtonStartingId());
94 button->SetUserData(userData);
95 button->SetOn(select,kFALSE);
98 //_____________________________________________________________________________
100 AliMUONPainterInterfaceHelper::ClearButtons(TGButtonGroup& bg)
102 /// Remove all buttons from group.
103 /// Bear in mind that you're thus disconnecting the group from
104 /// any signals it might have. So you must re-connect them after
105 /// a call to this method, if you want to.
107 while ( bg.GetCount() > 0 )
109 TGTextButton* button = (TGTextButton*)(bg.GetButton(bg.GetCount()));
112 AliFatalClass(Form("Got a null button for bg.Count()=%d",bg.GetCount()));
115 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,16,0)
116 button->DestroyWindow();
122 //_____________________________________________________________________________
124 AliMUONPainterInterfaceHelper::Copy(const TGButtonGroup& src, TGButtonGroup& dest)
126 /// Copy a button group into another one
127 AliDebugClass(1,Form("src=%p (%s) count=%d dest=%p (%s) count=%d",
128 &src,src.GetTitle(),src.GetCount(),
129 &dest,dest.GetTitle(),dest.GetCount()));
131 StdoutToAliDebugClass(1,cout << "---copying:" << endl; Dump(src);
132 cout << "---to:" << endl; Dump(dest));
136 dest.SetTitle(src.GetTitle());
140 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + src.GetCount(); ++i )
142 TGTextButton* tb = static_cast<TGTextButton*>(src.GetButton(i));
143 TGButton* button = new TGRadioButton(&dest,tb->GetTitle(),tb->WidgetId());
144 assert(tb->WidgetId()==i);
145 button->SetUserData(tb->GetUserData());
146 button->SetOn(tb->IsOn(),kFALSE);
151 //_____________________________________________________________________________
153 AliMUONPainterInterfaceHelper::Dump(const TGButtonGroup& bg)
156 cout << Form("ButtonGroup %s %s",bg.GetName(),bg.GetTitle()) << endl;
158 for ( Int_t i = ButtonStartingId(); i < bg.GetCount() + ButtonStartingId(); ++i )
160 TGTextButton* button = static_cast<TGTextButton*>(bg.GetButton(i));
163 cout << Form("i %2d button %s id %lu wid %d ON %d",
164 i,button->GetTitle(),button->GetId(),
166 button->IsOn()) << endl;
170 cout << Form("i %2d button = 0x0",i) << endl;
175 //_____________________________________________________________________________
177 AliMUONPainterInterfaceHelper::FindButtonByName(const TGButtonGroup& bg,
180 /// Find a button by name
182 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
184 TGTextButton* button = static_cast<TGTextButton*>(bg.GetButton(i));
187 AliErrorClass(Form("(%s) : Something wrong",name.Data()));
192 if ( name == button->GetTitle() )
201 //_____________________________________________________________________________
203 AliMUONPainterInterfaceHelper::FindButtonByUserData(const TGButtonGroup& bg,
204 const void* userData)
206 /// Find a button by userData
208 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
210 TGButton* button = bg.GetButton(i);
211 if ( button->GetUserData() == userData )
219 //_____________________________________________________________________________
221 AliMUONPainterInterfaceHelper::FindDownButton(const TGButtonGroup& bg)
223 /// Find which button is down (in a radio group)
225 AliDebugClass(1,Form("bg %s",bg.GetTitle()));
227 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
229 TGButton* button = bg.GetButton(i);
230 if ( button->IsOn() )
232 AliDebugClass(1,Form("button %s",button->GetTitle()));
240 //_____________________________________________________________________________
242 AliMUONPainterInterfaceHelper::SetBackgroundColor(const char* resourceBaseName,
245 /// Set the background color of the window
246 TString rs(Form("%s.BackgroundColor",resourceBaseName));
247 TString colorName = AliMUONPainterHelper::Instance()->Env()->String(rs.Data(),"#c0c0c0");
250 Bool_t ok = gClient->GetColorByName(colorName, color);
253 window.SetBackgroundColor(color);
254 AliDebugClass(1,Form("Setting %s color to %s",rs.Data(),colorName.Data()));
258 //_____________________________________________________________________________
260 AliMUONPainterInterfaceHelper::SetState(TGButtonGroup& bg, Bool_t state)
262 /// should not be needed with root > 5.16/00 as there's a TGButtonGroup::SetState
265 #if ROOT_VERSION_CODE > ROOT_VERSION(5,16,0)
268 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
270 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
273 button->SetState(kButtonUp);
277 button->SetState(kButtonDisabled);
283 //_____________________________________________________________________________
285 AliMUONPainterInterfaceHelper::Select(TGButtonGroup& bg,
286 const TString& buttonName,
289 /// Select which button should be on
291 AliDebugClass(1,Form("bg %s buttonName %s",bg.GetTitle(),buttonName.Data()));
293 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
295 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
296 if ( buttonName == button->GetTitle() || buttonName == "*" )
304 button->SetOn(kTRUE);
310 //_____________________________________________________________________________
312 AliMUONPainterInterfaceHelper::Unselect(TGButtonGroup& bg,
313 const TString& buttonName,
316 /// Unselect a given button
318 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
320 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
321 if ( buttonName == button->GetTitle() || buttonName == "*" )
329 button->SetOn(kFALSE);
335 //_____________________________________________________________________________
337 AliMUONPainterInterfaceHelper::RemoveButton(TGButtonGroup& bg,
338 const TGButton* button)
342 // need to redo it from scratch in order not the leave holes in the
345 TGButtonGroup bgtmp(bg.GetParent(),bg.GetTitle());
347 Int_t id(ButtonStartingId());
349 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
351 TGTextButton* b = static_cast<TGTextButton*>(bg.GetButton(i));
355 TGButton* bc = new TGRadioButton(&bgtmp,b->GetTitle(),id);
357 bc->SetUserData(b->GetUserData());
358 bc->SetOn(b->IsOn());