]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPainterInterfaceHelper.cxx
Bug fix (selection of RawReaderDate from Yuri was not correct)
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterInterfaceHelper.cxx
CommitLineData
0145e89a 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
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**************************************************************************/
15
16// $Id$
17
18#include "AliMUONPainterInterfaceHelper.h"
19
20///\class AliMUONPainterInterfaceHelper
21///
22/// Helper class to work with TGButtonGroup
23///
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.
29///
30// Author Laurent Aphecetche, Subatech
31
32#include "AliMUONPainterEnv.h"
33#include "AliMUONPainterHelper.h"
34#include "AliLog.h"
35#include <Riostream.h>
36#include <TClass.h>
37#include <TGButtonGroup.h>
38#include <TGButton.h>
39#include <TGClient.h>
40#include <TObjArray.h>
41#include <TObjString.h>
42#include <TString.h>
43#include <RVersion.h>
44#include <cassert>
45
46///\cond CLASSIMP
47ClassImp(AliMUONPainterInterfaceHelper)
48///\endcond
49
50//_____________________________________________________________________________
51AliMUONPainterInterfaceHelper::AliMUONPainterInterfaceHelper() : TObject()
52{
53 /// ctor
54}
55
56//_____________________________________________________________________________
57AliMUONPainterInterfaceHelper::~AliMUONPainterInterfaceHelper()
58{
59 /// dtor
60}
61
62//_____________________________________________________________________________
63void
64AliMUONPainterInterfaceHelper::AddRadioButton(TGButtonGroup& bg,
65 const TString& name,
66 void* userData,
67 Bool_t select)
68{
69 /// Add a radio button to a group
70 Int_t n = bg.GetCount();
71
72 TGButton* button = new TGRadioButton(&bg,
73 name.Data(),
74 n+ButtonStartingId());
75 button->SetUserData(userData);
76 button->SetOn(select,kFALSE);
77}
78
79//_____________________________________________________________________________
80void
81AliMUONPainterInterfaceHelper::AddCheckButton(TGButtonGroup& bg,
82 const TString& name,
83 void* userData,
84 Bool_t select)
85{
86 /// Add a check button to a group
87 Int_t n = bg.GetCount();
88
89 TGButton* button = new TGCheckButton(&bg,
90 name.Data(),
91 n+ButtonStartingId());
92 button->SetUserData(userData);
93 button->SetOn(select,kFALSE);
94}
95
96//_____________________________________________________________________________
97void
98AliMUONPainterInterfaceHelper::ClearButtons(TGButtonGroup& bg)
99{
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.
104
105 while ( bg.GetCount() > 0 )
106 {
107 TGTextButton* button = (TGTextButton*)(bg.GetButton(bg.GetCount()));
108 if ( !button )
109 {
110 AliFatalClass(Form("Got a null button for bg.Count()=%d",bg.GetCount()));
111 }
112 bg.Remove(button);
113#if ROOT_VERSION_CODE <= ROOT_VERSION(5,16,0)
114 button->DestroyWindow();
115#endif
116 delete button;
117 }
118}
119
120//_____________________________________________________________________________
121void
122AliMUONPainterInterfaceHelper::Copy(const TGButtonGroup& src, TGButtonGroup& dest)
123{
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()));
128
129 StdoutToAliDebugClass(1,cout << "---copying:" << endl; Dump(src);
130 cout << "---to:" << endl; Dump(dest));
131
132 ClearButtons(dest);
133
134 dest.SetTitle(src.GetTitle());
135
136 if ( &src != &dest )
137 {
138 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + src.GetCount(); ++i )
139 {
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);
145 }
146 }
147}
148
149//_____________________________________________________________________________
150void
151AliMUONPainterInterfaceHelper::Dump(const TGButtonGroup& bg)
152{
153 /// Printout
154 cout << Form("ButtonGroup %s %s",bg.GetName(),bg.GetTitle()) << endl;
155
156 for ( Int_t i = ButtonStartingId(); i < bg.GetCount() + ButtonStartingId(); ++i )
157 {
158 TGTextButton* button = static_cast<TGTextButton*>(bg.GetButton(i));
159 cout << Form("i %2d button %s id %d wid %d ON %d",
160 i,button->GetTitle(),button->GetId(),
161 button->WidgetId(),
162 button->IsOn()) << endl;
163 }
164}
165
166//_____________________________________________________________________________
167TGButton*
168AliMUONPainterInterfaceHelper::FindButtonByName(const TGButtonGroup& bg,
169 const TString& name)
170{
171 /// Find a button by name
172
173 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
174 {
175 TGTextButton* button = static_cast<TGTextButton*>(bg.GetButton(i));
176 if ( name == button->GetTitle() )
177 {
178 return button;
179 }
180 }
181 return 0x0;
182}
183
184//_____________________________________________________________________________
185TGButton*
186AliMUONPainterInterfaceHelper::FindButtonByUserData(const TGButtonGroup& bg,
187 void* userData)
188{
189 /// Find a button by userData
190
191 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
192 {
193 TGButton* button = bg.GetButton(i);
194 if ( button->GetUserData() == userData )
195 {
196 return button;
197 }
198 }
199 return 0x0;
200}
201
202//_____________________________________________________________________________
203TGButton*
204AliMUONPainterInterfaceHelper::FindDownButton(const TGButtonGroup& bg)
205{
206 /// Find which button is down (in a radio group)
207
208 AliDebugClass(1,Form("bg %s",bg.GetTitle()));
209
210 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
211 {
212 TGButton* button = bg.GetButton(i);
213 if ( button->IsOn() )
214 {
215 AliDebugClass(1,Form("button %s",button->GetTitle()));
216 return button;
217 }
218 }
219 return 0x0;
220}
221
222
223//_____________________________________________________________________________
224void
225AliMUONPainterInterfaceHelper::SetBackgroundColor(const char* resourceBaseName,
226 TGWindow& window)
227{
228 /// Set the background color of the window
229 TString rs(Form("%s.BackgroundColor",resourceBaseName));
230 TString colorName = AliMUONPainterHelper::Instance()->Env()->String(rs.Data(),"#c0c0c0");
231
232 Pixel_t color;
233 Bool_t ok = gClient->GetColorByName(colorName, color);
234 if ( ok )
235 {
236 window.SetBackgroundColor(color);
237 AliDebugClass(1,Form("Setting %s color to %s",rs.Data(),colorName.Data()));
238 }
239}
240
241//_____________________________________________________________________________
242void
243AliMUONPainterInterfaceHelper::SetState(TGButtonGroup& bg, Bool_t state)
244{
245 /// should not be needed with root > 5.16/00 as there's a TGButtonGroup::SetState
246 /// method now...
247
248#if ROOT_VERSION_CODE > ROOT_VERSION(5,16,0)
249 bg.SetState(state);
250#else
251 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
252 {
253 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
254 if ( state )
255 {
256 button->SetState(kButtonUp);
257 }
258 else
259 {
260 button->SetState(kButtonDisabled);
261 }
262 }
263#endif
264}
265
266//_____________________________________________________________________________
267void
268AliMUONPainterInterfaceHelper::Select(TGButtonGroup& bg,
269 const TString& buttonName,
270 Bool_t emit)
271{
272 /// Select which button should be on
273
274 AliDebugClass(1,Form("bg %s buttonName %s",bg.GetTitle(),buttonName.Data()));
275
276 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
277 {
278 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
279 if ( buttonName == button->GetTitle() || buttonName == "*" )
280 {
281 if ( emit )
282 {
283 button->Clicked();
284 }
285 else
286 {
287 button->SetOn(kTRUE);
288 }
289 }
290 }
291}
292
293//_____________________________________________________________________________
294void
295AliMUONPainterInterfaceHelper::Unselect(TGButtonGroup& bg,
296 const TString& buttonName,
297 Bool_t emit)
298{
299 /// Unselect a given button
300
301 for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i )
302 {
303 TGTextButton* button = (TGTextButton*)(bg.GetButton(i));
304 if ( buttonName == button->GetTitle() || buttonName == "*" )
305 {
306 if ( emit )
307 {
308 button->Released();
309 }
310 else
311 {
312 button->SetOn(kFALSE);
313 }
314 }
315 }
316}
317