2 // Author: Matevz Tadel 2007
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 **************************************************************************/
10 #include "AliEveMacroExecutorWindow.h"
11 #include "AliEveMacroExecutor.h"
12 #include "AliEveMacro.h"
13 #include "AliEveEventManager.h"
15 #include <TGedEditor.h>
17 #include <TGListBox.h>
18 #include <TGTextEntry.h>
23 class AliEveMEWListBox : public TGListBox
26 AliEveMEWListBox(const TGWindow* p = 0, Int_t id = -1) : TGListBox(p, id)
30 const TGGC& old = TGTextLBEntry::GetDefaultGC();
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()));
38 using TGListBox::AddEntry;
39 virtual void AddEntry(const char* s, Int_t id)
41 static const Pixel_t gkBackground[] = { 0x00ffffff, 0xf5f7f8 };
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]);
53 static TGFont *gfFont;
56 AliEveMEWListBox(const AliEveMEWListBox&); // Not implemented
57 AliEveMEWListBox& operator=(const AliEveMEWListBox&); // Not implemented
60 TGGC *AliEveMEWListBox::gfGC = 0;
61 TGFont *AliEveMEWListBox::gfFont = 0;
64 class AliEveMEWEditor : public TGedEditor
67 AliEveMEWEditor(AliEveMacroExecutorWindow* w) : TGedEditor(0), fMEW(w) {}
68 virtual ~AliEveMEWEditor() {}
69 virtual void Update(TGedFrame* gframe=0)
71 TGedEditor::Update(gframe);
72 fMEW->PopulateMacros();
74 virtual void Refresh()
76 SetModel(fPad, fModel, kButton1Down);
79 AliEveMacroExecutorWindow* fMEW;
81 AliEveMEWEditor(const AliEveMEWEditor&); // Not implemented
82 AliEveMEWEditor& operator=(const AliEveMEWEditor&); // Not implemented
85 //______________________________________________________________________________
86 // Full description of AliEveMacroExecutorWindow
89 ClassImp(AliEveMacroExecutorWindow)
91 //______________________________________________________________________________
92 AliEveMacroExecutorWindow::AliEveMacroExecutorWindow(AliEveMacroExecutor* master) :
93 TGMainFrame(gClient->GetRoot()), fM(master),
94 fMainFrame(0), fCtrlFrame(0), fListBox(0), fEditor(0),
100 fMainFrame = new TGVerticalFrame(this);
101 AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
103 // TGHorizontalFrame *f = 0;
106 fCtrlFrame = MkHFrame(fMainFrame);
107 fCtrlFrame->Resize(400, 22);
109 b = new TGTextButton(fCtrlFrame, "Reload event");
110 fCtrlFrame->AddFrame(b);
111 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
114 MkLabel(fCtrlFrame, "Select: ", 48);
115 fSelectTags = new TGTextEntry(fCtrlFrame);
116 fCtrlFrame->AddFrame(fSelectTags, new TGLayoutHints(kLHintsNormal));//|kLHintsExpandX));
117 fSelectTags->Connect("ReturnPressed()", "AliEveMacroExecutorWindow", this,
119 b = new TGTextButton(fCtrlFrame, "Select");
120 fCtrlFrame->AddFrame(b);
121 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
124 b = new TGTextButton(fCtrlFrame, "Enable all");
125 fCtrlFrame->AddFrame(b);
126 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
129 b = new TGTextButton(fCtrlFrame, "Disable all");
130 fCtrlFrame->AddFrame(b);
131 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
135 fListBox = new AliEveMEWListBox(fMainFrame);
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)");
141 fMainFrame->SetEditDisabled(kEditEnable);
142 fMainFrame->SetEditable();
143 fEditor = new AliEveMEWEditor(this);
144 fEditor->SetGlobal(kFALSE);
145 fMainFrame->SetEditable(kEditDisable);
146 fMainFrame->SetEditable(kFALSE);
148 TGFrameElement *el = 0;
149 TIter next(fMainFrame->GetList());
150 while ((el = (TGFrameElement *) next())) {
151 if (el->fFrame == fEditor)
153 el->fLayout->SetLayoutHints(kLHintsExpandX);
154 el->fLayout->SetPadLeft(1); el->fLayout->SetPadRight(1);
155 el->fLayout->SetPadTop(2); el->fLayout->SetPadBottom(2);
160 fEditor->Resize(400, 150);
161 fEditor->ChangeOptions(fEditor->GetOptions() | kFixedHeight);
165 SetCleanup(kDeepCleanup);
170 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveMacroExecutorWindow", this,
174 AliEveMacroExecutorWindow::~AliEveMacroExecutorWindow()
178 AliEveEventManager::GetMaster()->Disconnect("NewEventLoaded()", this);
181 /******************************************************************************/
183 void AliEveMacroExecutorWindow::PopulateMacros(Bool_t keep_selected)
185 // Populate list-box (or whatever will replace it) with all macros.
186 // prototype: no selection, sorting
188 // printf("AliEveMacroExecutorWindow::PopulateMacros()\n");
190 AliEveMacro* ex_sel = 0;
191 if (keep_selected && fListBox->GetSelected() != -1)
192 ex_sel = fBoxContents[fListBox->GetSelected()];
194 fListBox->RemoveAll();
195 fBoxContents.clear();
197 TPMERegexp *regexp = 0;
198 TString select = fSelectTags->GetText();
199 if ( ! select.IsNull())
201 regexp = new TPMERegexp(select, "io");
204 TIter next(fM->fMacros);
208 while ((mac = (AliEveMacro*) next()))
210 if (regexp && regexp->Match(mac->GetTags()) == 0)
215 fListBox->AddEntry(mac->FormForDisplay(), id++);
216 fBoxContents.push_back(mac);
220 fListBox->Select(sel_id);
222 fListBox->MapSubwindows();
226 void AliEveMacroExecutorWindow::SetActiveStateOfShownMacros(Bool_t active)
228 // Set active-state of all shown macros to active.
229 // Automatically refreshes the list and editor.
231 for (std::vector<AliEveMacro*>::iterator m = fBoxContents.begin(); m != fBoxContents.end(); ++m)
232 (*m)->SetActive(active);
237 /******************************************************************************/
239 void AliEveMacroExecutorWindow::NewEventLoaded()
241 // Slot called after a new event has been loaded
243 // !!! Once we have exit status from the macro, can update GUI showing this.
246 void AliEveMacroExecutorWindow::DoReloadEvent()
248 // Slot for reload-event.
250 AliEveEventManager::GetMaster()->GotoEvent(AliEveEventManager::GetMaster()->GetEventId());
253 void AliEveMacroExecutorWindow::DoSelectTags()
255 // Slot for select-tags.
260 void AliEveMacroExecutorWindow::DoMacroSelected(Int_t mid)
262 // Slot for macro-selected.
264 fEditor->SetModel(0, fBoxContents[mid], kButton1Down);
267 /******************************************************************************/
269 TGHorizontalFrame* AliEveMacroExecutorWindow::MkHFrame(TGCompositeFrame* p)
271 // Make standard horizontal frame.
275 TGHorizontalFrame* f = new TGHorizontalFrame(p);
276 p->AddFrame(f, new TGLayoutHints(kLHintsNormal|kLHintsExpandX));
280 TGLabel* AliEveMacroExecutorWindow::MkLabel(TGCompositeFrame* p, const char* txt, Int_t width,
281 Int_t lo, Int_t ro, Int_t to, Int_t bo)
283 // Make standard label.
285 TGLabel *l = new TGLabel(p, txt);
286 p->AddFrame(l, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
287 l->SetTextJustify(kTextRight);
289 l->ChangeOptions(l->GetOptions() | kFixedWidth);