]>
Commit | Line | Data |
---|---|---|
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 | ||
b80faac0 | 46 | using std::cout; |
47 | using std::endl; | |
0145e89a | 48 | ///\cond CLASSIMP |
49 | ClassImp(AliMUONPainterInterfaceHelper) | |
50 | ///\endcond | |
51 | ||
52 | //_____________________________________________________________________________ | |
53 | AliMUONPainterInterfaceHelper::AliMUONPainterInterfaceHelper() : TObject() | |
54 | { | |
55 | /// ctor | |
56 | } | |
57 | ||
58 | //_____________________________________________________________________________ | |
59 | AliMUONPainterInterfaceHelper::~AliMUONPainterInterfaceHelper() | |
60 | { | |
61 | /// dtor | |
62 | } | |
63 | ||
64 | //_____________________________________________________________________________ | |
65 | void | |
66 | AliMUONPainterInterfaceHelper::AddRadioButton(TGButtonGroup& bg, | |
67 | const TString& name, | |
68 | void* userData, | |
69 | Bool_t select) | |
70 | { | |
71 | /// Add a radio button to a group | |
72 | Int_t n = bg.GetCount(); | |
73 | ||
74 | TGButton* button = new TGRadioButton(&bg, | |
75 | name.Data(), | |
76 | n+ButtonStartingId()); | |
77 | button->SetUserData(userData); | |
78 | button->SetOn(select,kFALSE); | |
79 | } | |
80 | ||
81 | //_____________________________________________________________________________ | |
82 | void | |
83 | AliMUONPainterInterfaceHelper::AddCheckButton(TGButtonGroup& bg, | |
84 | const TString& name, | |
85 | void* userData, | |
86 | Bool_t select) | |
87 | { | |
88 | /// Add a check button to a group | |
89 | Int_t n = bg.GetCount(); | |
90 | ||
91 | TGButton* button = new TGCheckButton(&bg, | |
92 | name.Data(), | |
93 | n+ButtonStartingId()); | |
94 | button->SetUserData(userData); | |
95 | button->SetOn(select,kFALSE); | |
96 | } | |
97 | ||
98 | //_____________________________________________________________________________ | |
99 | void | |
100 | AliMUONPainterInterfaceHelper::ClearButtons(TGButtonGroup& bg) | |
101 | { | |
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. | |
106 | ||
107 | while ( bg.GetCount() > 0 ) | |
108 | { | |
109 | TGTextButton* button = (TGTextButton*)(bg.GetButton(bg.GetCount())); | |
110 | if ( !button ) | |
111 | { | |
112 | AliFatalClass(Form("Got a null button for bg.Count()=%d",bg.GetCount())); | |
113 | } | |
114 | bg.Remove(button); | |
115 | #if ROOT_VERSION_CODE <= ROOT_VERSION(5,16,0) | |
116 | button->DestroyWindow(); | |
117 | #endif | |
118 | delete button; | |
119 | } | |
120 | } | |
121 | ||
122 | //_____________________________________________________________________________ | |
123 | void | |
124 | AliMUONPainterInterfaceHelper::Copy(const TGButtonGroup& src, TGButtonGroup& dest) | |
125 | { | |
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())); | |
130 | ||
131 | StdoutToAliDebugClass(1,cout << "---copying:" << endl; Dump(src); | |
132 | cout << "---to:" << endl; Dump(dest)); | |
133 | ||
134 | ClearButtons(dest); | |
135 | ||
136 | dest.SetTitle(src.GetTitle()); | |
137 | ||
138 | if ( &src != &dest ) | |
139 | { | |
140 | for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + src.GetCount(); ++i ) | |
141 | { | |
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); | |
147 | } | |
148 | } | |
149 | } | |
150 | ||
151 | //_____________________________________________________________________________ | |
152 | void | |
153 | AliMUONPainterInterfaceHelper::Dump(const TGButtonGroup& bg) | |
154 | { | |
155 | /// Printout | |
156 | cout << Form("ButtonGroup %s %s",bg.GetName(),bg.GetTitle()) << endl; | |
157 | ||
158 | for ( Int_t i = ButtonStartingId(); i < bg.GetCount() + ButtonStartingId(); ++i ) | |
159 | { | |
160 | TGTextButton* button = static_cast<TGTextButton*>(bg.GetButton(i)); | |
49419555 | 161 | if ( button ) |
162 | { | |
a4ecce1e | 163 | cout << Form("i %2d button %s id %lu wid %d ON %d", |
0145e89a | 164 | i,button->GetTitle(),button->GetId(), |
165 | button->WidgetId(), | |
166 | button->IsOn()) << endl; | |
49419555 | 167 | } |
168 | else | |
169 | { | |
170 | cout << Form("i %2d button = 0x0",i) << endl; | |
171 | } | |
0145e89a | 172 | } |
173 | } | |
174 | ||
175 | //_____________________________________________________________________________ | |
176 | TGButton* | |
177 | AliMUONPainterInterfaceHelper::FindButtonByName(const TGButtonGroup& bg, | |
178 | const TString& name) | |
179 | { | |
180 | /// Find a button by name | |
181 | ||
182 | for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i ) | |
183 | { | |
184 | TGTextButton* button = static_cast<TGTextButton*>(bg.GetButton(i)); | |
49419555 | 185 | if (!button) |
0145e89a | 186 | { |
49419555 | 187 | AliErrorClass(Form("(%s) : Something wrong",name.Data())); |
188 | Dump(bg); | |
189 | } | |
190 | else | |
191 | { | |
192 | if ( name == button->GetTitle() ) | |
193 | { | |
194 | return button; | |
195 | } | |
0145e89a | 196 | } |
197 | } | |
198 | return 0x0; | |
199 | } | |
200 | ||
201 | //_____________________________________________________________________________ | |
202 | TGButton* | |
203 | AliMUONPainterInterfaceHelper::FindButtonByUserData(const TGButtonGroup& bg, | |
57e2ad1a | 204 | const void* userData) |
0145e89a | 205 | { |
206 | /// Find a button by userData | |
207 | ||
208 | for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i ) | |
209 | { | |
210 | TGButton* button = bg.GetButton(i); | |
211 | if ( button->GetUserData() == userData ) | |
212 | { | |
213 | return button; | |
214 | } | |
215 | } | |
216 | return 0x0; | |
217 | } | |
218 | ||
219 | //_____________________________________________________________________________ | |
220 | TGButton* | |
221 | AliMUONPainterInterfaceHelper::FindDownButton(const TGButtonGroup& bg) | |
222 | { | |
223 | /// Find which button is down (in a radio group) | |
224 | ||
225 | AliDebugClass(1,Form("bg %s",bg.GetTitle())); | |
226 | ||
227 | for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i ) | |
228 | { | |
229 | TGButton* button = bg.GetButton(i); | |
230 | if ( button->IsOn() ) | |
231 | { | |
232 | AliDebugClass(1,Form("button %s",button->GetTitle())); | |
233 | return button; | |
234 | } | |
235 | } | |
236 | return 0x0; | |
237 | } | |
238 | ||
239 | ||
240 | //_____________________________________________________________________________ | |
241 | void | |
242 | AliMUONPainterInterfaceHelper::SetBackgroundColor(const char* resourceBaseName, | |
243 | TGWindow& window) | |
244 | { | |
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"); | |
248 | ||
249 | Pixel_t color; | |
250 | Bool_t ok = gClient->GetColorByName(colorName, color); | |
251 | if ( ok ) | |
252 | { | |
253 | window.SetBackgroundColor(color); | |
254 | AliDebugClass(1,Form("Setting %s color to %s",rs.Data(),colorName.Data())); | |
255 | } | |
256 | } | |
257 | ||
258 | //_____________________________________________________________________________ | |
259 | void | |
260 | AliMUONPainterInterfaceHelper::SetState(TGButtonGroup& bg, Bool_t state) | |
261 | { | |
262 | /// should not be needed with root > 5.16/00 as there's a TGButtonGroup::SetState | |
263 | /// method now... | |
264 | ||
265 | #if ROOT_VERSION_CODE > ROOT_VERSION(5,16,0) | |
266 | bg.SetState(state); | |
267 | #else | |
268 | for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i ) | |
269 | { | |
270 | TGTextButton* button = (TGTextButton*)(bg.GetButton(i)); | |
271 | if ( state ) | |
272 | { | |
273 | button->SetState(kButtonUp); | |
274 | } | |
275 | else | |
276 | { | |
277 | button->SetState(kButtonDisabled); | |
278 | } | |
279 | } | |
280 | #endif | |
281 | } | |
282 | ||
283 | //_____________________________________________________________________________ | |
284 | void | |
285 | AliMUONPainterInterfaceHelper::Select(TGButtonGroup& bg, | |
286 | const TString& buttonName, | |
287 | Bool_t emit) | |
288 | { | |
289 | /// Select which button should be on | |
290 | ||
291 | AliDebugClass(1,Form("bg %s buttonName %s",bg.GetTitle(),buttonName.Data())); | |
292 | ||
293 | for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i ) | |
294 | { | |
295 | TGTextButton* button = (TGTextButton*)(bg.GetButton(i)); | |
296 | if ( buttonName == button->GetTitle() || buttonName == "*" ) | |
297 | { | |
298 | if ( emit ) | |
299 | { | |
300 | button->Clicked(); | |
301 | } | |
302 | else | |
303 | { | |
304 | button->SetOn(kTRUE); | |
305 | } | |
306 | } | |
307 | } | |
308 | } | |
309 | ||
310 | //_____________________________________________________________________________ | |
311 | void | |
312 | AliMUONPainterInterfaceHelper::Unselect(TGButtonGroup& bg, | |
313 | const TString& buttonName, | |
314 | Bool_t emit) | |
315 | { | |
316 | /// Unselect a given button | |
317 | ||
318 | for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i ) | |
319 | { | |
320 | TGTextButton* button = (TGTextButton*)(bg.GetButton(i)); | |
321 | if ( buttonName == button->GetTitle() || buttonName == "*" ) | |
322 | { | |
323 | if ( emit ) | |
324 | { | |
325 | button->Released(); | |
326 | } | |
327 | else | |
328 | { | |
329 | button->SetOn(kFALSE); | |
330 | } | |
331 | } | |
332 | } | |
333 | } | |
334 | ||
49419555 | 335 | //_____________________________________________________________________________ |
336 | void | |
337 | AliMUONPainterInterfaceHelper::RemoveButton(TGButtonGroup& bg, | |
57e2ad1a | 338 | const TGButton* button) |
49419555 | 339 | { |
340 | /// Remove a button | |
341 | ||
342 | // need to redo it from scratch in order not the leave holes in the | |
343 | // id numbering | |
344 | ||
345 | TGButtonGroup bgtmp(bg.GetParent(),bg.GetTitle()); | |
346 | ||
347 | Int_t id(ButtonStartingId()); | |
348 | ||
349 | for ( Int_t i = ButtonStartingId(); i < ButtonStartingId() + bg.GetCount(); ++i ) | |
350 | { | |
351 | TGTextButton* b = static_cast<TGTextButton*>(bg.GetButton(i)); | |
352 | ||
353 | if ( b != button ) | |
354 | { | |
355 | TGButton* bc = new TGRadioButton(&bgtmp,b->GetTitle(),id); | |
356 | ++id; | |
357 | bc->SetUserData(b->GetUserData()); | |
358 | bc->SetOn(b->IsOn()); | |
359 | } | |
360 | } | |
361 | ||
362 | ClearButtons(bg); | |
363 | ||
364 | Copy(bgtmp,bg); | |
365 | ||
366 | bg.Show(); | |
367 | } |