Fix effc++ warnings.
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveMacroExecutorWindow.cxx
CommitLineData
f6afd0e1 1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
9
10#include "AliEveMacroExecutorWindow.h"
11#include "AliEveMacroExecutor.h"
12#include "AliEveMacro.h"
13#include "AliEveEventManager.h"
14
15#include <TGedEditor.h>
7b2d546e 16#include <TGLabel.h>
f6afd0e1 17#include <TGListBox.h>
7b2d546e 18#include <TGTextEntry.h>
f6afd0e1 19#include <Buttons.h>
20
7b2d546e 21#include <TPRegexp.h>
22
4578afcb 23class AliEveMEWListBox : public TGListBox
f6afd0e1 24{
25public:
4578afcb 26 AliEveMEWListBox(const TGWindow* p = 0, Int_t id = -1) : TGListBox(p, id)
27 {
28 if (gfGC == 0)
29 {
30 const TGGC& old = TGTextLBEntry::GetDefaultGC();
31
32 gfFont = gClient->GetFontPool()->GetFont("-*-lucidatypewriter-*-*-*-*-12-*-*-*-*-*-iso8859-1");
33 gfGC = gClient->GetGCPool()->GetGC((GCValues_t*) old.GetAttributes(), kTRUE);
34 gfGC->SetFont(gVirtualX->GetFontHandle(gfFont->GetFontStruct()));
35 }
36 }
37
38 using TGListBox::AddEntry;
39 virtual void AddEntry(const char* s, Int_t id)
40 {
41 static const Pixel_t gkBackground[] = { 0x00ffffff, 0xf5f7f8 };
42
43 TGTextLBEntry *lbe = new TGTextLBEntry(fLbc, new TGString(s), id,
44 gfGC->GetGC(), gfFont->GetFontStruct());
45 fItemVsize = TMath::Max(fItemVsize, lbe->GetDefaultHeight());
46 fLbc->AddEntry(lbe, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
47 // Need to set it here as the above line sets it to white (for some strange reason).
48 lbe->SetBackgroundColor(gkBackground[id%2]);
49 }
50
51protected:
52 static TGGC *gfGC;
53 static TGFont *gfFont;
3607f2fb 54
55private:
56 AliEveMEWListBox(const AliEveMEWListBox&); // Not implemented
57 AliEveMEWListBox& operator=(const AliEveMEWListBox&); // Not implemented
f6afd0e1 58};
59
4578afcb 60TGGC *AliEveMEWListBox::gfGC = 0;
61TGFont *AliEveMEWListBox::gfFont = 0;
62
63
7b2d546e 64class AliEveMEWEditor : public TGedEditor
f6afd0e1 65{
f6afd0e1 66public:
7b2d546e 67 AliEveMEWEditor(AliEveMacroExecutorWindow* w) : TGedEditor(0), fMEW(w) {}
68 virtual ~AliEveMEWEditor() {}
f6afd0e1 69 virtual void Update(TGedFrame* gframe=0)
70 {
71 TGedEditor::Update(gframe);
72 fMEW->PopulateMacros();
73 }
7b2d546e 74 virtual void Refresh()
75 {
76 SetModel(fPad, fModel, kButton1Down);
77 }
3607f2fb 78protected:
79 AliEveMacroExecutorWindow* fMEW;
80private:
81 AliEveMEWEditor(const AliEveMEWEditor&); // Not implemented
82 AliEveMEWEditor& operator=(const AliEveMEWEditor&); // Not implemented
f6afd0e1 83};
f6afd0e1 84
85//______________________________________________________________________________
86// Full description of AliEveMacroExecutorWindow
87//
88
89ClassImp(AliEveMacroExecutorWindow)
90
91//______________________________________________________________________________
92AliEveMacroExecutorWindow::AliEveMacroExecutorWindow(AliEveMacroExecutor* master) :
93 TGMainFrame(gClient->GetRoot()), fM(master),
7b2d546e 94 fMainFrame(0), fCtrlFrame(0), fListBox(0), fEditor(0),
3607f2fb 95 fSelectTags(0),
96 fBoxContents()
f6afd0e1 97{
98 // Constructor.
99
100 fMainFrame = new TGVerticalFrame(this);
101 AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
102
4578afcb 103 // TGHorizontalFrame *f = 0;
104 TGButton *b = 0;
f6afd0e1 105 {
7b2d546e 106 fCtrlFrame = MkHFrame(fMainFrame);
107 fCtrlFrame->Resize(400, 22);
f6afd0e1 108
7b2d546e 109 b = new TGTextButton(fCtrlFrame, "Reload event");
f6afd0e1 110 fCtrlFrame->AddFrame(b);
111 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
112 "DoReloadEvent()");
7b2d546e 113
4578afcb 114 MkLabel(fCtrlFrame, "Select: ", 48);
115 fSelectTags = new TGTextEntry(fCtrlFrame);
116 fCtrlFrame->AddFrame(fSelectTags, new TGLayoutHints(kLHintsNormal));//|kLHintsExpandX));
117 fSelectTags->Connect("ReturnPressed()", "AliEveMacroExecutorWindow", this,
7b2d546e 118 "DoSelectTags()");
119 b = new TGTextButton(fCtrlFrame, "Select");
120 fCtrlFrame->AddFrame(b);
121 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
122 "DoSelectTags()");
123
124 b = new TGTextButton(fCtrlFrame, "Enable all");
125 fCtrlFrame->AddFrame(b);
126 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
127 "DoEnableAll()");
128
129 b = new TGTextButton(fCtrlFrame, "Disable all");
130 fCtrlFrame->AddFrame(b);
131 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
132 "DoDisableAll()");
f6afd0e1 133 }
134
4578afcb 135 fListBox = new AliEveMEWListBox(fMainFrame);
f6afd0e1 136 fMainFrame->AddFrame(fListBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
137 fListBox->Resize(400, 400);
138 fListBox->Connect("Selected(Int_t)", "AliEveMacroExecutorWindow", this,
139 "DoMacroSelected(Int_t)");
140
141 fMainFrame->SetEditDisabled(kEditEnable);
142 fMainFrame->SetEditable();
7b2d546e 143 fEditor = new AliEveMEWEditor(this);
f6afd0e1 144 fEditor->SetGlobal(kFALSE);
145 fMainFrame->SetEditable(kEditDisable);
146 fMainFrame->SetEditable(kFALSE);
147 {
148 TGFrameElement *el = 0;
149 TIter next(fMainFrame->GetList());
150 while ((el = (TGFrameElement *) next())) {
151 if (el->fFrame == fEditor)
152 if (el->fLayout) {
153 el->fLayout->SetLayoutHints(kLHintsExpandX);
154 el->fLayout->SetPadLeft(1); el->fLayout->SetPadRight(1);
155 el->fLayout->SetPadTop(2); el->fLayout->SetPadBottom(2);
156 break;
157 }
158 }
159 }
4578afcb 160 fEditor->Resize(400, 150);
f6afd0e1 161 fEditor->ChangeOptions(fEditor->GetOptions() | kFixedHeight);
162
163 Resize(400, 700);
164
165 SetCleanup(kDeepCleanup);
166 Layout();
167 MapSubwindows();
168 MapWindow();
169
4d62585e 170 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveMacroExecutorWindow", this,
f6afd0e1 171 "NewEventLoaded()");
172}
173
174AliEveMacroExecutorWindow::~AliEveMacroExecutorWindow()
175{
176 // Destructor.
177
4d62585e 178 AliEveEventManager::GetMaster()->Disconnect("NewEventLoaded()", this);
f6afd0e1 179}
180
181/******************************************************************************/
182
183void AliEveMacroExecutorWindow::PopulateMacros(Bool_t keep_selected)
184{
185 // Populate list-box (or whatever will replace it) with all macros.
186 // prototype: no selection, sorting
187
188 // printf("AliEveMacroExecutorWindow::PopulateMacros()\n");
189
190 AliEveMacro* ex_sel = 0;
191 if (keep_selected && fListBox->GetSelected() != -1)
192 ex_sel = fBoxContents[fListBox->GetSelected()];
193
194 fListBox->RemoveAll();
195 fBoxContents.clear();
196
7b2d546e 197 TPMERegexp *regexp = 0;
198 TString select = fSelectTags->GetText();
199 if ( ! select.IsNull())
200 {
4578afcb 201 // "i" does not work (get pcre_exec error = -3 PCRE_ERROR_BADOPTION)
202 // same for 1 (the value of PCRE_CASELESS)
203 // using case-sensitive matching then ... must investigate in root
204 regexp = new TPMERegexp(select);
7b2d546e 205 }
f6afd0e1 206
207 TIter next(fM->fMacros);
208 AliEveMacro *mac;
209 Int_t id = 0;
210 Int_t sel_id = -1;
211 while ((mac = (AliEveMacro*) next()))
212 {
7b2d546e 213 if (regexp && regexp->Match(mac->GetTags()) == 0)
214 continue;
f6afd0e1 215 if (mac == ex_sel)
216 sel_id = id;
7b2d546e 217
f6afd0e1 218 fListBox->AddEntry(mac->FormForDisplay(), id++);
219 fBoxContents.push_back(mac);
220 }
221
222 if (sel_id != -1)
223 fListBox->Select(sel_id);
224
225 fListBox->MapSubwindows();
226 fListBox->Layout();
227}
228
7b2d546e 229void AliEveMacroExecutorWindow::SetActiveStateOfShownMacros(Bool_t active)
230{
231 // Set active-state of all shown macros to active.
232 // Automatically refreshes the list and editor.
233
234 for (std::vector<AliEveMacro*>::iterator m = fBoxContents.begin(); m != fBoxContents.end(); ++m)
235 (*m)->SetActive(active);
236 PopulateMacros();
237 fEditor->Refresh();
238}
239
f6afd0e1 240/******************************************************************************/
241
242void AliEveMacroExecutorWindow::NewEventLoaded()
243{
244 // Slot called after a new event has been loaded
245
246 // !!! Once we have exit status from the macro, can update GUI showing this.
247}
248
249void AliEveMacroExecutorWindow::DoReloadEvent()
250{
251 // Slot for reload-event.
252
4d62585e 253 AliEveEventManager::GetMaster()->GotoEvent(AliEveEventManager::GetMaster()->GetEventId());
f6afd0e1 254}
255
7b2d546e 256void AliEveMacroExecutorWindow::DoSelectTags()
257{
258 // Slot for select-tags.
259
260 PopulateMacros();
261}
262
f6afd0e1 263void AliEveMacroExecutorWindow::DoMacroSelected(Int_t mid)
264{
265 // Slot for macro-selected.
266
267 fEditor->SetModel(0, fBoxContents[mid], kButton1Down);
268}
7b2d546e 269
270/******************************************************************************/
271
272TGHorizontalFrame* AliEveMacroExecutorWindow::MkHFrame(TGCompositeFrame* p)
273{
274 // Make standard horizontal frame.
275
276 if (p == 0)
277 p = this;
278 TGHorizontalFrame* f = new TGHorizontalFrame(p);
279 p->AddFrame(f, new TGLayoutHints(kLHintsNormal|kLHintsExpandX));
280 return f;
281}
282
283TGLabel* AliEveMacroExecutorWindow::MkLabel(TGCompositeFrame* p, const char* txt, Int_t width,
284 Int_t lo, Int_t ro, Int_t to, Int_t bo)
285{
286 // Make standard label.
287
288 TGLabel *l = new TGLabel(p, txt);
289 p->AddFrame(l, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
290 l->SetTextJustify(kTextRight);
291 l->SetWidth(width);
292 l->ChangeOptions(l->GetOptions() | kFixedWidth);
293 return l;
294}