source: trunk/Mars/mbase/MStatusDisplay.cc@ 10107

Last change on this file since 10107 was 10055, checked in by tbretz, 14 years ago
Display canvas title in status line.
File size: 99.3 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 4/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2003-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MStatusDisplay
28//
29// This status display can be used (and is used) to display results in
30// a tabbed window. The window can be written to and read from a root file
31// (see Read and Write) or printed as a postscript file (see SaveAsPS).
32//
33// To write gif files of C-Macros use SaveAsGif()/SaveAsPNG() or SaveAsC().
34// Direct printing to the default printer (via lpr) can be done by
35// PrintPS().
36//
37// It has also to half status lines which can be used to display the status
38// or something going on. Together with the status lines it has a progress
39// bar which can display the progress of a job or loop.
40// Access the progress bar by GetProgressBar()
41//
42// To add a new tab and get a pointer to the newly created TCanvas
43// use AddTab.
44//
45// If you have a MStatusDisplay and you are not sure whether it was
46// destroyed by the user meanwhile use:
47// gROOT->GetListOfSpecials()->FindObject(pointer);
48// Each MStatusDisplay is added to list list by its constructor and
49// removed from the list by the destructor.
50//
51// You can redirect an output to a MLog-logstream by calling SetLogStream().
52// To disable redirction call SetLogStream(NULL)
53//
54// Because updates to the tabs are only done/displayed if a tab is active
55// using the gui doesn't make things slower (<1%) if the first (legend
56// tab) is displayed. This gives you the possibility to look into
57// the current progress of a loop without loosing more time than the
58// single update of the tab.
59//
60/////////////////////////////////////////////////////////////////////////////
61#include "MStatusDisplay.h"
62
63#include <errno.h>
64#include <stdlib.h> // mktemp (Ubunto 8.10)
65
66#include <fstream> // fstream
67
68#include <TH1.h> // TH1::AddDirectory
69#include <TPDF.h> // TPDF
70#include <TSVG.h> // TSVG
71#include <TEnv.h> // TEnv
72#include <TLine.h> // TLine
73#include <TMath.h>
74#include <TText.h> // TText
75#include <TFile.h> // gFile
76#include <TFrame.h> // TFrame
77#include <TStyle.h> // gStyle
78#include <TCanvas.h> // TCanvas
79#include <TSystem.h> // gSystem
80#include <TDatime.h> // TDatime
81#include <TRandom.h> // TRandom
82#include <TRegexp.h> // TRegexp
83#include <TThread.h> // TThread::Self()
84#include <TBrowser.h> // TBrowser
85#include <TObjArray.h> // TObjArray
86#include <TPostScript.h> // TPostScript
87#include <TMethodCall.h> // TMethodCall
88
89#include <TInterpreter.h> // gInterpreter
90
91#include <TGTab.h> // TGTab
92#include <TGLabel.h> // TGLabel
93#include <TG3DLine.h> // TGHorizontal3DLine
94#include <TGButton.h> // TGPictureButton
95#include <TGTextView.h> // TGTextView
96#include <TGComboBox.h> // TGComboBox
97#include <TGStatusBar.h> // TGStatusBar
98#include <TGFileDialog.h> // TGFileDialog
99#include <TGProgressBar.h> // TGHProgressBar
100#include <TGTextEditDialogs.h> // TGPrintDialog
101#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
102
103#include "MString.h"
104
105#include "MLog.h" // MLog
106#include "MLogManip.h" // inf, warn, err
107
108#include "MGList.h" // MGList
109#include "MGMenu.h" // MGMenu, TGMenu
110#include "MSearch.h" // MSearch
111#include "MParContainer.h" // MParContainer::GetDescriptor
112#include "MStatusArray.h" // MStatusArray
113
114#if ROOT_VERSION_CODE <= ROOT_VERSION(5,22,00)
115#include "../mhbase/MH.h"
116#endif
117
118#undef DEBUG
119//#define DEBUG
120
121ClassImp(MStatusDisplay);
122
123using namespace std;
124
125// ------------ Workaround for a non working TGTextView::Search -------------
126#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,05)
127class MGTextView : public TGTextView
128{
129public:
130 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, Int_t id = -1,
131 UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
132 TGTextView(parent, w, h, id, sboptions, back) {}
133 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
134 Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
135 TGTextView(parent, w, h, text, id, sboptions, back) {}
136 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
137 Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
138 TGTextView(parent, w, h, string, id, sboptions, back) {}
139
140 void Mark(Long_t xPos, Long_t yPos) { TGTextView::Mark(xPos, yPos); }
141 void UnMark() { TGTextView::UnMark(); }
142
143 Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive)
144 {
145 // Taken from TGTextView::Search and modified.
146
147 TGLongPosition pos, pos2;
148 pos2.fX = pos2.fY = 0;
149 if (fIsMarked) {
150 if (!direction)
151 {
152 pos2.fX = fMarkedStart.fX;
153 pos2.fY = fMarkedStart.fY;
154 }
155 else
156 {
157 pos2.fX = fMarkedEnd.fX + 1;
158 pos2.fY = fMarkedEnd.fY;
159 }
160 }
161 if (!fText->Search(&pos, pos2, string, direction, caseSensitive))
162 return kFALSE;
163 UnMark();
164 fIsMarked = kTRUE;
165 fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
166 fMarkedStart.fX = pos.fX;
167 fMarkedEnd.fX = fMarkedStart.fX + strlen(string);
168 pos.fY = ToObjYCoord(fVisible.fY);
169 if ((fMarkedStart.fY < pos.fY) ||
170 (ToScrYCoord(fMarkedStart.fY) >= (Int_t)fCanvas->GetHeight()))
171 pos.fY = fMarkedStart.fY;
172 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
173 if ((fMarkedStart.fX < pos.fX) ||
174 (ToScrXCoord(fMarkedStart.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()))
175 pos.fX = fMarkedStart.fX;
176
177 SetVsbPosition((ToScrYCoord(pos.fY) + fVisible.fY)/fScrollVal.fY);
178 SetHsbPosition((ToScrXCoord(pos.fX, pos.fY) + fVisible.fX)/fScrollVal.fX);
179 DrawRegion(0, (Int_t)ToScrYCoord(fMarkedStart.fY), fCanvas->GetWidth(),
180 UInt_t(ToScrYCoord(fMarkedEnd.fY+1) - ToScrYCoord(fMarkedEnd.fY)));
181
182 return kTRUE;
183 }
184};
185#else
186#define MGTextView TGTextView
187#endif
188
189// --------------------------------------------------------------------------
190
191TGCompositeFrame *MStatusDisplay::GetTabContainer(const char *name) const
192{
193#if ROOT_VERSION_CODE < ROOT_VERSION(4,03,05)
194 if (!fTab)
195 return 0;
196
197 TGFrameElement *el;
198 TGTabElement *tab = 0;
199 TGCompositeFrame *comp = 0;
200
201 TIter next(fTab->GetList());
202 next(); // skip first container
203
204 while ((el = (TGFrameElement *) next())) {
205 el = (TGFrameElement *) next();
206 comp = (TGCompositeFrame *) el->fFrame;
207 next();
208 tab = (TGTabElement *)el->fFrame;
209 if (name == tab->GetText()->GetString()) {
210 return comp;
211 }
212 }
213
214 return 0;
215#else
216 return fTab ? fTab->GetTabContainer(name) : 0;
217#endif
218}
219
220TGTabElement *MStatusDisplay::GetTabTab(const char *name) const
221{
222#if ROOT_VERSION_CODE < ROOT_VERSION(4,03,05)
223 if (!fTab)
224 return 0;
225
226 TGFrameElement *el;
227 TGTabElement *tab = 0;
228
229 TIter next(fTab->GetList());
230 next(); // skip first container
231
232 while ((el = (TGFrameElement *) next())) {
233 next();
234 tab = (TGTabElement *)el->fFrame;
235 if (name == tab->GetText()->GetString()) {
236 return tab;
237 }
238 }
239
240 return 0;
241#else
242 return fTab ? fTab->GetTabTab(name) : 0;
243#endif
244}
245// --------------------------------------------------------------------------
246
247
248// --------------------------------------------------------------------------
249//
250// Add menu bar to the GUI
251//
252void MStatusDisplay::AddMenuBar()
253{
254 //
255 // File Menu
256 //
257 MGPopupMenu *filemenu = new MGPopupMenu(gClient->GetRoot());
258 filemenu->AddEntry("New &Canvas", kFileCanvas);
259 filemenu->AddEntry("New &Browser", kFileBrowser);
260 filemenu->AddEntry("New &Tab", kFileTab);
261 filemenu->AddSeparator();
262
263 const TString fname(MString::Format("Save %s.", gROOT->GetName()));
264 MGPopupMenu *savemenu = new MGPopupMenu(gClient->GetRoot());
265 savemenu->AddEntry(MString::Format("%s&ps", fname.Data()), kFileSaveAsPS);
266 savemenu->AddEntry(MString::Format("%sp&df", fname.Data()), kFileSaveAsPDF);
267 savemenu->AddEntry(MString::Format("%s&svg", fname.Data()), kFileSaveAsSVG);
268 savemenu->AddSeparator();
269 savemenu->AddEntry(MString::Format("%sp&ng", fname.Data()), kFileSaveAsPNG);
270 savemenu->AddEntry(MString::Format("%s&gif", fname.Data()), kFileSaveAsGIF);
271 savemenu->AddEntry(MString::Format("%s&jpg", fname.Data()), kFileSaveAsJPG);
272 savemenu->AddEntry(MString::Format("%s&xpm", fname.Data()), kFileSaveAsXPM);
273 savemenu->AddEntry(MString::Format("%s&tiff",fname.Data()), kFileSaveAsTIFF);
274 savemenu->AddEntry(MString::Format("%s&bmp", fname.Data()), kFileSaveAsBMP);
275 savemenu->AddEntry(MString::Format("%sx&ml", fname.Data()), kFileSaveAsXML);
276 savemenu->AddEntry(MString::Format("%scs&v", fname.Data()), kFileSaveAsCSV);
277 savemenu->AddSeparator();
278 savemenu->AddEntry(MString::Format("%s&C", fname.Data()), kFileSaveAsC);
279 savemenu->AddEntry(MString::Format("%s&root", fname.Data()), kFileSaveAsRoot);
280 savemenu->AddEntry(MString::Format("%s&root (plain)", fname.Data()), kFileSaveAsPlainRoot);
281 savemenu->Associate(this);
282
283 filemenu->AddEntry("&Open...", kFileOpen);
284 filemenu->AddPopup("&Save", savemenu);
285 filemenu->AddEntry("Save &As...", kFileSaveAs);
286 filemenu->AddSeparator();
287 filemenu->AddEntry("&Reset", kFileReset);
288 filemenu->AddSeparator();
289 filemenu->AddEntry("&Print", kFilePrint);
290 filemenu->AddSeparator();
291 filemenu->AddEntry("C&lose", kFileClose);
292 filemenu->AddEntry("E&xit", kFileExit);
293 filemenu->Associate(this);
294
295 //
296 // Tab Menu
297 //
298 MGPopupMenu *tabmenu = new MGPopupMenu(gClient->GetRoot());
299 tabmenu->AddEntry("Next [&+]", kTabNext);
300 tabmenu->AddEntry("Previous [&-]", kTabPrevious);
301 tabmenu->AddSeparator();
302
303 const TString fname2(MString::Format("Save %s-i.", gROOT->GetName()));
304 MGPopupMenu *savemenu2 = new MGPopupMenu(gClient->GetRoot());
305 savemenu2->AddEntry(MString::Format("%s&ps", fname2.Data()), kTabSaveAsPS);
306 savemenu2->AddEntry(MString::Format("%sp&df", fname2.Data()), kTabSaveAsPDF);
307 savemenu2->AddEntry(MString::Format("%s&svg", fname2.Data()), kTabSaveAsSVG);
308 savemenu2->AddSeparator();
309 savemenu2->AddEntry(MString::Format("%sp&ng", fname2.Data()), kTabSaveAsPNG);
310 savemenu2->AddEntry(MString::Format("%s&gif", fname2.Data()), kTabSaveAsGIF);
311 savemenu2->AddEntry(MString::Format("%s&jpg", fname2.Data()), kTabSaveAsJPG);
312 savemenu2->AddEntry(MString::Format("%s&xpm", fname2.Data()), kTabSaveAsXPM);
313 savemenu2->AddEntry(MString::Format("%s&tiff",fname2.Data()), kTabSaveAsTIFF);
314 savemenu2->AddEntry(MString::Format("%s&bmp", fname2.Data()), kTabSaveAsBMP);
315 savemenu2->AddEntry(MString::Format("%sx&ml", fname2.Data()), kTabSaveAsXML);
316 savemenu2->AddEntry(MString::Format("%scs&v", fname2.Data()), kTabSaveAsCSV);
317 savemenu2->AddSeparator();
318 savemenu2->AddEntry(MString::Format("%s&C", fname2.Data()), kTabSaveAsC);
319 savemenu2->AddEntry(MString::Format("%s&root", fname2.Data()), kTabSaveAsRoot);
320 savemenu2->Associate(this);
321
322 tabmenu->AddPopup("&Save", savemenu2);
323 tabmenu->AddEntry("Save tab &As...", kTabSaveAs);
324 tabmenu->AddSeparator();
325 tabmenu->AddEntry("&Remove", kTabRemove);
326 tabmenu->AddSeparator();
327 tabmenu->AddEntry("&Print", kTabPrint);
328 tabmenu->Associate(this);
329
330 //
331 // Loop Menu
332 //
333 MGPopupMenu *loopmenu = new MGPopupMenu(gClient->GetRoot());
334 loopmenu->AddEntry("&Pause", kLoopPause);
335 loopmenu->AddEntry("Single S&tep", kLoopStep);
336 loopmenu->AddSeparator();
337 loopmenu->AddEntry("&Stop", kLoopStop);
338 loopmenu->Associate(this);
339
340 loopmenu->DisableEntry(kLoopStep);
341
342 //
343 // Loop Menu
344 //
345 MGPopupMenu *sizemenu = new MGPopupMenu(gClient->GetRoot());
346 sizemenu->AddEntry("Fit to 640x&480", kSize640);
347 sizemenu->AddEntry("Fit to 768x&576", kSize768);
348 sizemenu->AddEntry("Fit to 800x&600", kSize800);
349 sizemenu->AddEntry("Fit to 960x7&20", kSize960);
350 sizemenu->AddEntry("Fit to 1024x&768", kSize1024);
351 sizemenu->AddEntry("Fit to 1152x&864", kSize1152);
352 sizemenu->AddEntry("Fit to 1280x&1024", kSize1280);
353 sizemenu->AddEntry("Fit to 1400x1050", kSize1400);
354 sizemenu->AddEntry("Fit to 1600x1200", kSize1600);
355 sizemenu->AddEntry("Fit to &Desktop", kSizeOptimum);
356 sizemenu->Associate(this);
357
358 //
359 // Log Menu
360 //
361 MGPopupMenu *logmenu = new MGPopupMenu(gClient->GetRoot());
362 logmenu->AddEntry("&Copy Selected", kLogCopy);
363 logmenu->AddEntry("Cl&ear all", kLogClear);
364 logmenu->AddSeparator();
365 logmenu->AddEntry("Select &All", kLogSelect);
366 logmenu->AddSeparator();
367 logmenu->AddEntry("&Find...", kLogFind);
368 logmenu->AddSeparator();
369 logmenu->AddEntry("&Save", kLogSave);
370 logmenu->AddEntry("Save &append", kLogAppend);
371 logmenu->AddSeparator();
372 logmenu->AddEntry("&Print", kLogPrint);
373 logmenu->Associate(this);
374
375 //
376 // Menu Bar
377 //
378 TGLayoutHints *layitem = new TGLayoutHints(kLHintsNormal, 0, 4, 0, 0);
379 fList->Add(layitem);
380
381 fMenuBar = new MGMenuBar(this, 1, 1, kHorizontalFrame);
382 fMenuBar->AddPopup("&File", filemenu, layitem);
383 fMenuBar->AddPopup("Lo&g", logmenu, layitem);
384 fMenuBar->AddPopup("&Size", sizemenu, layitem);
385 fMenuBar->AddPopup("&Tab", tabmenu, layitem);
386 fMenuBar->AddPopup("&Loop", loopmenu, layitem);
387 fMenuBar->BindKeys(this);
388 AddFrame(fMenuBar);
389
390 //
391 // Line below menu bar
392 //
393 TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
394 fList->Add(laylinesep);
395
396 TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
397 AddFrame(linesep, laylinesep);
398
399 //
400 // Add everything to autodel list
401 //
402 fList->Add(savemenu);
403 fList->Add(savemenu2);
404 fList->Add(filemenu);
405 fList->Add(loopmenu);
406 fList->Add(sizemenu);
407 fList->Add(fMenuBar);
408 fList->Add(tabmenu);
409 fList->Add(logmenu);
410 fList->Add(linesep);
411}
412
413// --------------------------------------------------------------------------
414//
415// Adds an empty TGCompositeFrame which might be filled by the user
416//
417void MStatusDisplay::AddUserFrame()
418{
419 TGLayoutHints *lay=new TGLayoutHints(kLHintsExpandX);
420 fList->Add(lay);
421
422 fUserFrame = new TGCompositeFrame(this, 1, 1);
423 AddFrame(fUserFrame, lay);
424 fList->Add(fUserFrame);
425}
426
427// --------------------------------------------------------------------------
428//
429// Add the title tab
430//
431void MStatusDisplay::AddMarsTab()
432{
433 // Create Tab1
434 TGCompositeFrame *f = fTab->AddTab("-=MARS=-");
435
436 // Add list of tabs
437
438 TGComboBox *filter = new TGComboBox(f, kTabs);
439 fList->Add(filter);
440 filter->Associate(this);
441 filter->AddEntry("-=MARS=-", 0);
442 filter->Select(0);
443
444
445 TGLayoutHints *lay3 = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 10, 5);
446 fList->Add(lay3);
447 f->AddFrame(filter, lay3);
448
449 // Add MARS version
450 TGLabel *l = new TGLabel(f, MString::Format("Official Release: V%s", MARSVER));
451 fList->Add(l);
452
453 filter->SetWidth(5*l->GetWidth()/4);
454 filter->SetHeight(4*l->GetHeight()/3);
455 filter->GetListBox()->SetHeight(l->GetHeight()*16);
456
457 TGLayoutHints *layb = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 5, 5);
458 fList->Add(layb);
459 f->AddFrame(l, layb);
460
461 // Add root version
462 l = new TGLabel(f, MString::Format("Using ROOT v%s", ROOT_RELEASE));
463 fList->Add(l);
464
465 TGLayoutHints *lay = new TGLayoutHints(kLHintsCenterX|kLHintsTop);
466 fList->Add(lay);
467 f->AddFrame(l, lay);
468
469 // Add Mars logo picture
470 const TGPicture *pic2 = fList->GetPicture("marslogo.xpm");
471 if (pic2)
472 {
473 TGPictureButton *mars = new TGPictureButton(f, pic2, kPicMars);
474 fList->Add(mars);
475 mars->Associate(this);
476
477 TGLayoutHints *lay2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 10, 10, 5, 5);
478 fList->Add(lay2);
479 f->AddFrame(mars, lay2);
480 }
481
482 // Add date and time
483 l = new TGLabel(f, TDatime().AsString());
484 fList->Add(l);
485 f->AddFrame(l, lay);
486
487 // Add copyright notice
488 l = new TGLabel(f, MString::Format("(c) MARS Software Development, 2000-%d", TDatime().GetYear()));
489 fList->Add(l);
490 f->AddFrame(l, layb);
491
492 TGLayoutHints *layc = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 0, 5);
493 fList->Add(layc);
494
495 const char *txt = "<< Thomas Bretz >>";
496 l = new TGLabel(f, txt);
497 fList->Add(l);
498 f->AddFrame(l, layc);
499}
500
501// --------------------------------------------------------------------------
502//
503// Adds the logbook tab to the GUI if it was not added previously.
504//
505// The logbook is updated four times a second only if the tab is visible.
506//
507// You can redirect an output to a MLog-logstream by calling SetLogStream().
508// To disable redirction call SetLogStream(NULL)
509//
510// if enable==kFALSE the stdout is disabled/enabled. Otherwise stdout
511// is ignored.
512//
513void MStatusDisplay::SetLogStream(MLog *log, Bool_t enable)
514{
515 if (gROOT->IsBatch())
516 return;
517
518 if (log && fLogBox==NULL)
519 {
520 fLogIdx = fTab->GetNumberOfTabs();
521
522 // Create Tab1
523 TGCompositeFrame *f = AddRawTab("-Logbook-");//fTab->AddTab("-Logbook-");
524
525 // Create Text View
526 fLogBox = new MGTextView(f, 1, 1); // , -1, 0, TGFrame::GetDefaultFrameBackground());
527 if (fFont)
528 fLogBox->SetFont(fFont);
529 //fLogBox->Associate(this);
530
531 // Add List box to the tab
532 TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY,2,2,2,2);
533 f->AddFrame(fLogBox, lay);
534
535 // layout and map tab
536 Layout();
537 MapSubwindows();
538
539 // make it visible
540 // FIXME: This is a workaround, because TApplication::Run is not
541 // thread safe against ProcessEvents. We assume, that if
542 // we are not in the Main-Thread ProcessEvents() is
543 // called by the TApplication Event Loop...
544 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
545 gClient->ProcessEventsFor(fTab);
546 }
547
548 if (log)
549 {
550 fLog = log;
551
552 log->SetOutputGui(fLogBox, kTRUE);
553 log->EnableOutputDevice(MLog::eGui);
554 if (!enable)
555 log->DisableOutputDevice(MLog::eStdout);
556
557 fLogTimer.Start();
558 }
559 else
560 {
561 fLogTimer.Stop();
562
563 fLog->DisableOutputDevice(MLog::eGui);
564 fLog->SetOutputGui(NULL);
565 if (!enable)
566 fLog->EnableOutputDevice(MLog::eStdout);
567
568 fLog = &gLog;
569 }
570}
571
572// --------------------------------------------------------------------------
573//
574// Add the Tabs and the predifined Tabs to the GUI
575//
576void MStatusDisplay::AddTabs()
577{
578 fTab = new TGTab(this, 300, 300);
579
580 AddMarsTab();
581
582 // Add fTab to Frame
583 TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 5, 5, 5);
584 AddFrame(fTab, laytabs);
585
586 fList->Add(fTab);
587 fList->Add(laytabs);
588}
589
590// --------------------------------------------------------------------------
591//
592// Add the progress bar to the GUI. The Progress Bar range is set to
593// (0,1) as default.
594//
595void MStatusDisplay::AddProgressBar()
596{
597 TGLayoutHints *laybar=new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5);
598 fList->Add(laybar);
599
600 fBar=new TGHProgressBar(this);
601 fBar->SetRange(0, 1);
602 fBar->ShowPosition();
603 AddFrame(fBar, laybar);
604 fList->Add(fBar);
605}
606
607// --------------------------------------------------------------------------
608//
609// Set the progress bar position between 0 and 1. The Progress bar range
610// is assumed to be (0,1)
611//
612void MStatusDisplay::SetProgressBarPosition(Float_t p, Bool_t upd)
613{
614 if (!gClient || gROOT->IsBatch())
615 return;
616
617 fBar->SetPosition(p);
618 if (upd)
619 gClient->ProcessEventsFor(fBar);
620}
621
622// --------------------------------------------------------------------------
623//
624// Adds the status bar to the GUI
625//
626void MStatusDisplay::AddStatusBar()
627{
628 fStatusBar = new TGStatusBar(this, 1, 1);
629
630 //
631 // Divide it like the 'Golden Cut' (goldener Schnitt)
632 //
633 // 1-a a
634 // 1: ------|----
635 //
636 // a/(1-a) = (1-a)/1
637 // a^2+a-1 = 0
638 // a = (-1+-sqrt(1+4))/2 = sqrt(5)/2-1/2 = 0.618
639 //
640 Int_t p[] = {38-2, 62-8, 10};
641
642 fStatusBar->SetParts(p, 3);
643
644 TGLayoutHints *layb = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 4, 0, 3);
645 AddFrame(fStatusBar, layb);
646
647 fList->Add(fStatusBar);
648 fList->Add(layb);
649}
650
651// --------------------------------------------------------------------------
652//
653// Change the text in the status line 1
654//
655void MStatusDisplay::SetStatusLine(const char *txt, Int_t i)
656{
657 if (gROOT->IsBatch())
658 return;
659 fStatusBar->SetText(txt, i);
660
661 // FIXME: This is a workaround, because TApplication::Run is not
662 // thread safe against ProcessEvents. We assume, that if
663 // we are not in the Main-Thread ProcessEvents() is
664 // called by the TApplication Event Loop...
665 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
666 gClient->ProcessEventsFor(fStatusBar);
667}
668
669// --------------------------------------------------------------------------
670//
671// Display information about the name of a container
672//
673void MStatusDisplay::SetStatusLine2(const MParContainer &cont)
674{
675 SetStatusLine2(MString::Format("%s: %s", cont.GetDescriptor().Data(), cont.GetTitle()));
676}
677
678// --------------------------------------------------------------------------
679//
680// Get TGPopupMenu as defined by name from fMenuBar
681//
682TGPopupMenu *MStatusDisplay::GetPopup(const char *name)
683{
684 if (!fMenuBar)
685 return 0;
686
687 TGPopupMenu *m = fMenuBar->GetPopup(name);
688 if (!m)
689 {
690 *fLog << warn << name << " doesn't exist in menu bar." << endl;
691 return 0;
692 }
693
694 return m;
695}
696
697// --------------------------------------------------------------------------
698//
699// Default constructor. Opens a window with a progress bar. Get a pointer
700// to the bar by calling GetBar. This pointer can be used for the
701// eventloop.
702//
703// Be carefull: killing or closing the window while the progress meter
704// is still in use may cause segmentation faults. Please kill the window
705// always by deleting the corresponding object.
706//
707// You can give either width or height. (Set the value not given to -1)
708// The other value is calculated accordingly. If width and height are
709// given height is ignored. If width=height=0 an optimum size from
710// the desktop size is calculated.
711//
712// Update time default: 10s
713//
714MStatusDisplay::MStatusDisplay(Int_t w, Int_t h, Long_t t)
715: TGMainFrame((TGWindow*)((gClient?gClient:new TGClient),NULL), 1, 1), fName("MStatusDisplay"), fLog(&gLog), fBar(NULL), fTab(NULL), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0)
716{
717 // p==NULL means: Take gClient->GetRoot() if not in batch mode
718 // see TGWindow::TGWindow()
719
720 // Make sure that the display is removed via RecursiveRemove
721 // from whereever possible.
722 SetBit(kMustCleanup);
723
724 //
725 // This is a possibility for the user to check whether this
726 // object has already been deleted. It will be removed
727 // from the list in the destructor.
728 //
729 gROOT->GetListOfSpecials()->Add(this);
730
731 fFont = gVirtualX->LoadQueryFont("7x13bold");
732 fMutex = new TMutex;
733
734 //
735 // In case we are in batch mode use a list of canvases
736 // instead of the Root Embedded Canvases in the TGTab
737 //
738 fBatch = new TList;
739 fBatch->SetOwner();
740
741 //
742 // Create a list handling GUI widgets
743 //
744 fList = new MGList;
745 fList->SetOwner();
746
747 //
748 // Create the layout hint for the root embedded canavses
749 //
750 fLayCanvas = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
751 fList->Add(fLayCanvas);
752
753 //
754 // Add Widgets (from top to bottom)
755 //
756 // In newer root versions gClient!=NULL in batch mode!
757 if (!gClient || !gClient->GetRoot() || gROOT->IsBatch()) // BATCH MODE
758 {
759 Resize(644, 484);
760 return;
761 }
762
763 AddMenuBar();
764 AddUserFrame();
765 AddTabs();
766 AddProgressBar();
767 AddStatusBar();
768
769 //
770 // set the smallest and biggest size of the Main frame
771 // and move it to its appearance position
772 SetWMSizeHints(566, 476, 2048, 1536, 1, 1);
773 MoveResize(rand()%100+566, rand()%100+476, 566, 476);
774 if (h>0)
775 SetDisplayHeight(h);
776 if (w>0)
777 SetDisplayWidth(w);
778 if (w==0 && h==0)
779 SetOptimumSize();
780
781 //
782 // Now do an automatic layout of the widgets and display the window
783 //
784 Layout();
785 MapSubwindows();
786
787 SetWindowName("Status Display");
788 SetIconName("Status Display");
789
790 MapWindow();
791
792 UpdateMemory();
793
794 // FIXME: This is a workaround, because TApplication::Run is not
795 // thread safe against ProcessEvents. We assume, that if
796 // we are not in the Main-Thread ProcessEvents() is
797 // called by the TApplication Event Loop...
798 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
799 gSystem->ProcessEvents();
800}
801
802// --------------------------------------------------------------------------
803//
804// Destruct the window with all its tiles. Also the Progress Bar object
805// is deleted.
806//
807MStatusDisplay::~MStatusDisplay()
808{
809 fTimer.Stop();
810
811#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
812 fTab = NULL; // See HandleEvent
813#endif
814
815 //
816 // Delete object from global object table so it cannot
817 // be deleted by chance a second time
818 //
819 gInterpreter->DeleteGlobal(this);
820
821 //
822 // This is a possibility for the user to check whether this
823 // object has already been deleted. It has been added
824 // to the list in the constructor.
825 //
826 gROOT->GetListOfSpecials()->Remove(this);
827
828 SetLogStream(NULL);
829
830 //
831 // Delete the list of objects corresponding to this object
832 //
833 delete fList;
834
835 //
836 // Delete the list of canvases used in batch mode
837 // instead of the Root Embedded Canvases in the TGTab
838 //
839 delete fBatch;
840
841 //
842 // Delete the font used for the logging window
843 //
844 if (fFont)
845 gVirtualX->DeleteFont(fFont);
846
847 //
848 // Delete mutex
849 //
850 delete fMutex;
851}
852
853// --------------------------------------------------------------------------
854//
855// Takes a TGCompositeFrame as argument. Searches for the first
856// TRootEmbeddedCanvas which is contained by it and returns a pointer
857// to the corresponding TCanvas. If it isn't found NULL is returned.
858//
859TRootEmbeddedCanvas *MStatusDisplay::GetEmbeddedCanvas(TGCompositeFrame &cf)
860{
861 TIter Next(cf.GetList());
862
863 TGFrameElement *f;
864 while ((f=(TGFrameElement*)Next()))
865 if (f->fFrame->InheritsFrom(TRootEmbeddedCanvas::Class()))
866 return (TRootEmbeddedCanvas*)f->fFrame;
867
868 return NULL;
869}
870
871// --------------------------------------------------------------------------
872//
873// Takes a TGCompositeFrame as argument. Searches for the first
874// TRootEmbeddedCanvas which is contained by it and returns a pointer
875// to the corresponding TCanvas. If it isn't found NULL is returned.
876//
877TCanvas *MStatusDisplay::GetCanvas(TGCompositeFrame &cf)
878{
879 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(cf);
880 return ec ? ec->GetCanvas() : NULL;
881}
882
883// --------------------------------------------------------------------------
884//
885// Returns the range of tabs containing valid canvases for the condition
886// num.
887//
888void MStatusDisplay::GetCanvasRange(Int_t &from, Int_t &to, Int_t num) const
889{
890 const Int_t max = gROOT->IsBatch() ? fBatch->GetSize()+1 : fTab->GetNumberOfTabs();
891
892 from = num<0 ? 1 : num;
893 to = num<0 ? max : num+1;
894}
895
896// --------------------------------------------------------------------------
897//
898// Returns GetCanvas of the i-th Tab.
899//
900TCanvas *MStatusDisplay::GetCanvas(int i) const
901{
902 if (gROOT->IsBatch())
903 return (TCanvas*)fBatch->At(i-1);
904
905 if (i<0 || i>=fTab->GetNumberOfTabs())
906 {
907 *fLog << warn << "MStatusDisplay::GetCanvas: Out of range." << endl;
908 return NULL;
909 }
910
911 return GetCanvas(*fTab->GetTabContainer(i));
912}
913
914// --------------------------------------------------------------------------
915//
916// Returns j-th pad of the i-th Tab.
917// Sets the pad to fill an entire window.
918//
919// This function can be used if single pad's out of an MStatusDisplay
920// have to be stored to file.
921//
922// ATTENTION: This function modifies the requested tab in MStatusDisplay itself!
923//
924TVirtualPad *MStatusDisplay::GetFullPad(const Int_t i, const Int_t j)
925{
926 if (!GetCanvas(i))
927 {
928 *fLog << warn << "MStatusDisplay::GetFullPad: i-th canvas not dound." << endl;
929 return NULL;
930 }
931
932 TVirtualPad *vpad = GetCanvas(i)->GetPad(j);
933 if (!vpad)
934 {
935 *fLog << warn << "MStatusDisplay::GetFullPad: Pad is out of range." << endl;
936 return NULL;
937 }
938
939 vpad->SetPad(0.,0.,1.,1.);
940 return vpad;
941}
942
943// --------------------------------------------------------------------------
944//
945// Searches for a TRootEmbeddedCanvas in the TGCompositeFramme of the
946// Tab with the name 'name'. Returns the corresponding TCanvas or
947// NULL if something isn't found.
948//
949TCanvas *MStatusDisplay::GetCanvas(const TString &name) const
950{
951 if (gROOT->IsBatch())
952 return (TCanvas*)fBatch->FindObject(name);
953
954 TGFrameElement *f;
955 TIter Next(fTab->GetList());
956 while ((f=(TGFrameElement*)Next()))
957 {
958 TObject *frame = f->fFrame;
959 if (!frame->InheritsFrom(TGTabElement::Class()))
960 continue;
961
962 TGTabElement *tab = (TGTabElement*)frame;
963 if (tab->GetString()==name)
964 break;
965 }
966
967 // Search for the next TGCompositeFrame in the list
968 while ((f=(TGFrameElement*)Next()))
969 {
970 TObject *frame = f->fFrame;
971 if (frame->InheritsFrom(TGCompositeFrame::Class()))
972 return GetCanvas(*(TGCompositeFrame*)frame);
973 }
974
975 return NULL;
976}
977
978// --------------------------------------------------------------------------
979//
980// Calls TCanvas::cd(), for the canvas returned by GetCanvas.
981//
982Bool_t MStatusDisplay::CdCanvas(const TString &name)
983{
984 TCanvas *c = GetCanvas(name);
985 if (!c)
986 return kFALSE;
987
988 c->cd();
989 return kTRUE;
990}
991
992// --------------------------------------------------------------------------
993//
994// Return the number of user added tabs (not that in batch mode this
995// exclude tabs without a canvas)
996//
997Int_t MStatusDisplay::GetNumTabs() const
998{
999 return gROOT->IsBatch() ? fBatch->GetEntries() : fTab->GetNumberOfTabs()-1;
1000}
1001
1002TGCompositeFrame *MStatusDisplay::AddRawTab(const char *name)
1003{
1004 // Add new tab
1005 TGCompositeFrame *f = fTab->AddTab(name);
1006
1007 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
1008 box->AddEntry(name, box->GetListBox()->GetNumberOfEntries());
1009
1010 // layout and map new tab
1011 Layout();
1012 MapSubwindows();
1013 Layout();
1014
1015 UpdateMemory();
1016
1017 // display new tab in the main frame
1018 // FIXME: This is a workaround, because TApplication::Run is not
1019 // thread safe against ProcessEvents. We assume, that if
1020 // we are not in the Main-Thread ProcessEvents() is
1021 // called by the TApplication Event Loop...
1022 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
1023 gClient->ProcessEventsFor(fTab);
1024
1025 *fLog << inf3 << "Adding Raw Tab '" << name << "' (" << f->GetWidth() << "x";
1026 *fLog << f->GetHeight() << ")" << endl;
1027
1028 // return pointer to new canvas
1029 return f;
1030}
1031
1032// --------------------------------------------------------------------------
1033//
1034// This function was connected to all created canvases. It is used
1035// to redirect GetObjectInfo into our own status bar.
1036//
1037// The 'connection' is done in AddTab
1038//
1039void MStatusDisplay::EventInfo(Int_t /*event*/, Int_t px, Int_t py, TObject *selected)
1040{
1041 // Writes the event status in the status bar parts
1042 if (!selected)
1043 return;
1044
1045 TCanvas *c = (TCanvas*)gTQSender;
1046
1047 TVirtualPad* save=gPad;
1048
1049 gPad = c ? c->GetSelectedPad() : NULL;
1050
1051 if (gPad)
1052 {
1053 // Find the object which will get picked by the GetObjectInfo
1054 // due to buffer overflows in many root-versions
1055 // in TH1 and TProfile we have to work around and implement
1056 // our own GetObjectInfo which make everything a bit more
1057 // complicated.
1058#if ROOT_VERSION_CODE > ROOT_VERSION(5,22,00)
1059 SetStatusLine2(selected->GetObjectInfo(px,py));
1060#else
1061 TObjLink *link=0;
1062 static_cast<TPad*>(gPad)->Pick(px, py, link);
1063
1064 const TObject *o = link ? link->GetObject() : 0;
1065 if (o)
1066 SetStatusLine2(MH::GetObjectInfo(px, py, *o));
1067#endif
1068 }
1069
1070 gPad=save;
1071}
1072
1073// --------------------------------------------------------------------------
1074//
1075// Adds a new tab with the name 'name'. Adds a TRootEmbeddedCanvas to the
1076// tab and returns a reference to the corresponding TCanvas.
1077//
1078TCanvas &MStatusDisplay::AddTab(const char *name, const char *title)
1079{
1080 /*
1081 if (GetCanvas(name))
1082 {
1083 *fLog << warn;
1084 *fLog << "WARNING - A canvas '" << name << "' is already existing in the Status Display." << endl;
1085 *fLog << " This can cause unexpected crahes!" << endl;
1086 }*/
1087
1088 if (gROOT->IsBatch())
1089 {
1090 // 4 = 2*default border width of a canvas
1091 const UInt_t cw = GetWidth();
1092 const UInt_t ch = 2*cw/3 + 25; // 25: Menu, etc
1093
1094 // The constructor of TCanvas adds the canvas to the global list
1095 // of canvases gROOT->GetListOfCanvases(). If a canvas with an
1096 // identical name exists already in this list, the canvas is
1097 // deleted. In normal operation this might make sense and doesn't harm
1098 // because the embedded canvases behave different.
1099 // By creating the canvas without a name it is made sure that no
1100 // older canvas/tab vanished silently from the system (deleted from
1101 // the construtor). To make the handling of our canvases nevertheless
1102 // work well the name is set later. The list of canvases is also
1103 // part of the list of cleanups, thus fBatch need not to be added
1104 // to the list of cleanups.
1105 TCanvas *c = new TCanvas("", title?title:"", -cw, ch);
1106 c->SetName(name);
1107 c->SetFillColor(10); // White
1108 c->SetFrameBorderMode(0);
1109 c->SetBorderMode(0);
1110 fBatch->Add(c);
1111
1112 *fLog << inf3 << "Adding Canvas '" << name << "' (" << c->GetWw() << "x";
1113 *fLog << c->GetWh() << ", TCanvas=" << c << ")" << endl;
1114
1115 // Remove the canvas from the global list to make sure it is
1116 // not found by gROOT->FindObject
1117 //gROOT->GetListOfCanvases()->Remove(c);
1118 //gROOT->GetListOfCleanups()->Add(c);
1119
1120 return *c;
1121 }
1122
1123 // Add new tab
1124 TGCompositeFrame *f = fTab->AddTab(name);
1125
1126 // create root embedded canvas and add it to the tab
1127 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, f->GetWidth(), f->GetHeight(), kSunkenFrame);
1128 f->AddFrame(ec, fLayCanvas);
1129 fList->Add(ec);
1130
1131 // set background and border mode of the canvas
1132 TCanvas &c = *ec->GetCanvas();
1133
1134 if (title)
1135 c.SetTitle(title);
1136
1137 c.SetFillColor(10); // White
1138 c.SetFrameBorderMode(0);
1139 c.SetBorderMode(0);
1140
1141 // If kNoContextMenu set set kNoContextMenu of the canvas
1142 if (TestBit(kNoContextMenu))
1143 c.SetBit(kNoContextMenu);
1144
1145 // Connect all TCanvas::ProcessedEvent to this->EventInfo
1146 // This means, that after TCanvas has processed an event
1147 // EventInfo of this class is called, see TCanvas::HandleInput
1148 c.Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
1149 "MStatusDisplay", this, "EventInfo(Int_t,Int_t,Int_t,TObject*)");
1150
1151 // Make sure that root itself doesn't try to call GetObjectInfo
1152 // This is now handled from EventsInfo. This is necessary
1153 // due to the buffer overflow bug in GetObjectInfo of
1154 // TProfile and TH1
1155 c.ResetBit(TCanvas::kShowEventStatus);
1156
1157 // Remove the canvas from the global list to make sure it is
1158 // not found by gROOT->FindObject
1159 //gROOT->GetListOfCanvases()->Remove(&c);
1160 //gROOT->GetListOfCleanups()->Add(&c);
1161
1162 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
1163 box->AddEntry(name, box->GetListBox()->GetNumberOfEntries());
1164
1165 // layout and map new tab
1166 Layout(); // seems to layout the TGCompositeFrame
1167 MapSubwindows(); // maps the TGCompositeFrame
1168 Layout(); // layout the embedded canvas in the frame
1169
1170 UpdateMemory();
1171
1172 // display new tab in the main frame
1173 // FIXME: This is a workaround, because TApplication::Run is not
1174 // thread safe against ProcessEvents. We assume, that if
1175 // we are not in the Main-Thread ProcessEvents() is
1176 // called by the TApplication Event Loop...
1177 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
1178 gClient->ProcessEventsFor(fTab);
1179
1180 *fLog << inf3 << "Adding Tab '" << name << "' (" << f->GetWidth() << "x";
1181 *fLog << f->GetHeight() << ", TCanvas=" << &c << ")" << endl;
1182
1183 // return pointer to new canvas
1184 return c;
1185}
1186
1187// --------------------------------------------------------------------------
1188//
1189// Update a canvas in a tab, takes the corresponding TGCompositeFrame
1190// as an argument. This is necessary, because not all functions
1191// changing the contents of a canvas or pad can call SetModified()
1192// for the corresponding tab. If this is not called correctly the
1193// tab won't be updated calling TCanvas::Update(). So we simply
1194// redraw it by our own (instead we could recursively call
1195// TPad::Modified() for everything contained by the TCanvas and
1196// call TCanvas::Update() afterwards)
1197//
1198void MStatusDisplay::UpdateTab(TGCompositeFrame *f)
1199{
1200 if (!f)
1201 return;
1202
1203 TCanvas *c=GetCanvas(*f);
1204 if (!c)
1205 return;
1206
1207 const TString name = c->GetName();
1208 const TString title = c->GetTitle();
1209
1210 if (!title.IsNull() && name != title)
1211 SetStatusLine1(title);
1212
1213 //
1214 // If we are in a multithreaded environment (gThreadXAR) we
1215 // have to make sure, that thus function is called from
1216 // the main thread.
1217 //
1218 if (gThreadXAR)
1219 {
1220 // Tell the X-Requester how to call this method
1221 TString str = MString::Format("%d", (ULong_t)f);
1222
1223 TMethodCall call(IsA(), "UpdateTab", "NULL");
1224 void *arr[4] = { NULL, &call, this, (void*)(const char*)str };
1225
1226 // If this is not the main thread return
1227 if (((*gThreadXAR)("METH", 4, arr, NULL)))
1228 return;
1229 }
1230
1231 //
1232 // Secure calls to update the tabs against itself, at least
1233 // c->Paint() or c->Flush() may crash X (bad drawable).
1234 // This makes sure, that a X call is not interuppted by
1235 // another X-call which was started from an gui interrrupt
1236 // in the same thread
1237 //
1238 const Int_t rc = fMutex->TryLock();
1239 if (rc==13)
1240 gLog << warn << "MStatusDisplay::UpdateTab - mutex is already locked by this thread." << endl;
1241
1242 if (rc)
1243 return;
1244
1245#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
1246 TPad *padsav = (TPad*)gPad;
1247 if (!gPad)
1248 c->cd();
1249#endif
1250
1251 if (!c->IsBatch())
1252 c->FeedbackMode(kFALSE); // Goto double buffer mode
1253
1254 //
1255 // Doing this ourself gives us the possibility to repaint
1256 // the canvas in any case (Paint() instead of PaintModified())
1257 //
1258 c->Paint(); // Repaint all pads
1259 c->Flush(); // Copy all pad pixmaps to the screen
1260
1261#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
1262 if (padsav)
1263 padsav->cd();
1264 else
1265 gPad=NULL;
1266#endif
1267
1268 //c->SetCursor(kCross);
1269
1270 // Old version
1271 //c->Modified();
1272 //c->Update();
1273 //c->Paint();
1274
1275 fMutex->UnLock();
1276}
1277
1278TString MStatusDisplay::PrintDialog(TString &p, TString &c, TString &t, const char *ext)
1279{
1280 // If not in batch mode open a user dialog
1281 if (!gROOT->IsBatch())
1282 {
1283 char *cprinter = StrDup(p);
1284 char *ccmd = StrDup(c);
1285
1286 Int_t rc=0;
1287 new TGPrintDialog(fClient->GetRoot(), this, 400, 150, &cprinter, &ccmd, &rc);
1288 if (rc)
1289 {
1290 p = cprinter; // default has been changed
1291 c = ccmd;
1292 }
1293
1294 delete [] cprinter;
1295 delete [] ccmd;
1296
1297 if (!rc)
1298 return "";
1299 }
1300
1301 if (c.Contains("%f") && ext)
1302 {
1303 // Get temporary file name
1304 TString name = "mars";
1305
1306 FILE *f = gSystem->TempFileName(name, t);
1307 if (!f)
1308 {
1309 *fLog << warn << "MStatusDisplay::PrintDialog: Couldn't create temporary file in " << t << endl;
1310 SetStatusLine2("failed!");
1311 return "";
1312 }
1313 fclose(f);
1314
1315 // remove temp file
1316 gSystem->Unlink(name);
1317 name += ".";
1318 name += ext;
1319
1320 t = name;
1321 }
1322
1323 // compile command
1324 TString cmd(c);
1325
1326 // if sprinter.IsNull we assume that everything around %p can
1327 // be omitted and the program uses some kind of default
1328 if (p.IsNull())
1329 {
1330 TString sub;
1331 while (1)
1332 {
1333 sub = TString(cmd(TRegexp(" .*%p.* "))).Strip(TString::kBoth);
1334 if (sub.IsNull())
1335 break;
1336
1337 cmd.ReplaceAll(sub, "");
1338 }
1339 }
1340
1341 cmd.ReplaceAll("%p", p);
1342 cmd.ReplaceAll("%f", t);
1343
1344 return cmd;
1345}
1346
1347// --------------------------------------------------------------------------
1348//
1349// Saves the given canvas (pad) or all pads (num<0) as a temporary
1350// postscript file and prints it.
1351//
1352// The default command line c is: lpr -P%p %f
1353// %p: printer name
1354// %f: temporary file name
1355//
1356// The default printer name p is: <empty>
1357//
1358// Both can be changed in .rootrc by:
1359// PrintPS.Printer
1360// PrintPS.Command
1361//
1362// Ant the location of the temporary file t can by changed by
1363// Print.Directory
1364// the default is the system default directory (normally /tmp)
1365//
1366Int_t MStatusDisplay::PrintPS(Int_t num, const char *p, const char *c, const char *t)
1367{
1368 static TString sprinter = gEnv->GetValue("PrintPS.Printer", p&&*p?p:"");
1369 static TString scmd = gEnv->GetValue("PrintPS.Command", c&&*c?c:"lpr -P%p %f");
1370
1371 TString tmp = gEnv->GetValue("Print.Directory", t&&*t?t:gSystem->TempDirectory());
1372
1373 TString cmd = PrintDialog(sprinter, scmd, tmp, "ps");
1374 if (cmd.IsNull())
1375 return 0;
1376
1377 // set status lines
1378 SetStatusLine1("Printing...");
1379 SetStatusLine2("");
1380
1381 // print to temporary file
1382 const Int_t pages = SaveAsPS(num, tmp);
1383
1384 // check
1385 if (!pages)
1386 {
1387 *fLog << warn << "MStatusDisplay::Print: Sorry, couldn't save file as temporary postscript!" << endl;
1388 SetStatusLine2("Failed!");
1389 return 0;
1390 }
1391
1392 // execute command
1393 *fLog << dbg << "Executing: " << cmd << endl;
1394 gSystem->Exec(cmd);
1395
1396 // remove temporary file
1397 gSystem->Unlink(tmp);
1398
1399 SetStatusLine2(MString::Format("Done (%dpage(s))", pages));
1400
1401 return pages;
1402}
1403
1404// --------------------------------------------------------------------------
1405//
1406// Remove tab no i if this tab contains a TRootEmbeddedCanvas
1407//
1408void MStatusDisplay::RemoveTab(int i)
1409{
1410 TGCompositeFrame *f = fTab->GetTabContainer(i);
1411 if (!f)
1412 return;
1413
1414 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(*f);
1415 if (!ec)
1416 return;
1417
1418 TCanvas *c = ec->GetCanvas();
1419 if (!c)
1420 return;
1421
1422 // Repair the "Workaround" being in the RecursiveRemove list
1423 // but not in a list checked by gROOT->FindObject
1424 //gROOT->GetListOfCleanups()->Remove(c);
1425 //gROOT->GetListOfCanvases()->Add(c);
1426
1427 // FIXME: Due to our workaround this is necessary for a successfull deletion
1428 //c->cd();
1429
1430 const TString name(c->GetName());
1431
1432 f->RemoveFrame(ec);
1433 delete fList->Remove(ec);
1434
1435 fTab->RemoveTab(i);
1436 fTab->SetTab(0);
1437
1438 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
1439 box->RemoveEntry(i);
1440 for (int j=i; j<box->GetListBox()->GetNumberOfEntries(); j++)
1441 {
1442 TGTextLBEntry *entry = (TGTextLBEntry *)box->GetListBox()->Select(j+1, kFALSE);
1443 box->AddEntry(entry->GetText()->GetString(), j);
1444 box->RemoveEntry(j+1);
1445 }
1446 box->GetListBox()->Select(0);
1447
1448 // Looks strange...
1449 // const Int_t n = fTab->GetNumberOfTabs();
1450 // fTab->SetTab(i<=n-1 ? i : i-1);
1451
1452 // layout and map new tab
1453 Layout(); // seems to layout the TGCompositeFrame
1454 MapSubwindows(); // maps the TGCompositeFrame
1455 Layout(); // layout the embedded canvas in the frame
1456
1457 UpdateMemory();
1458
1459 // display new tab in the main frame
1460 // FIXME: This is a workaround, because TApplication::Run is not
1461 // thread safe against ProcessEvents. We assume, that if
1462 // we are not in the Main-Thread ProcessEvents() is
1463 // called by the TApplication Event Loop...
1464 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
1465 gClient->ProcessEventsFor(fTab);
1466
1467 *fLog << inf << "Removed Tab #" << i << " '" << name << "'" << endl;
1468}
1469
1470// --------------------------------------------------------------------------
1471//
1472// Use this to check whether the MStatusDisplay still contains the
1473// TCanvas c. It could be removed meanwhile by menu usage.
1474//
1475Bool_t MStatusDisplay::HasCanvas(const TCanvas *c) const
1476{
1477 if (!c)
1478 return kFALSE;
1479
1480 // If you encounter unexpected crashes here, check if
1481 // a canvas is existing twice in the list or has been
1482 // deleted by accident. (Check AddTab)
1483
1484 if (gROOT->IsBatch())
1485 return (Bool_t)fBatch->FindObject(c);
1486
1487 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
1488 if (c==GetCanvas(i))
1489 return kTRUE;
1490 return kFALSE;
1491}
1492
1493/*
1494 if (...)
1495 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1496 else
1497 fMenu->RemovePopup("CaOs");
1498 fMenu->Resize(fMenu->GetDefaultSize());
1499 MapSubwindows();
1500 MapWindow();
1501 */
1502
1503void MStatusDisplay::Reset()
1504{
1505 if (gROOT->IsBatch())
1506 {
1507 fBatch->Delete();
1508 return;
1509 }
1510
1511 for (int i=fTab->GetNumberOfTabs()-1; i>0; i--)
1512 RemoveTab(i);
1513}
1514
1515Bool_t MStatusDisplay::SaveLogAsPS(const char *n) const
1516{
1517 TString name(n);
1518 AddExtension(name, "ps");
1519
1520 // Code taken from TGTextEdit::Print
1521 const TString pipe = MString::Format("a2ps -o%s", name.Data());
1522 FILE *p = gSystem->OpenPipe(pipe, "w");
1523 if (!p)
1524 {
1525 *fLog << err << "ERROR - Couldn't open pipe " << pipe << ": " << strerror(errno) << endl;
1526 return kFALSE;
1527 }
1528
1529 TGText *text = fLogBox->GetText();
1530
1531 char *buf1, *buf2;
1532 Long_t len;
1533 ULong_t i = 0;
1534 TGLongPosition pos;
1535
1536 Bool_t rc = kTRUE;
1537
1538 pos.fX = pos.fY = 0;
1539 while (pos.fY < text->RowCount())
1540 {
1541 len = text->GetLineLength(pos.fY);
1542 buf1 = text->GetLine(pos, len);
1543 buf2 = new char[len + 2];
1544 strncpy(buf2, buf1, (UInt_t)len);
1545 buf2[len] = '\n';
1546 buf2[len+1] = '\0';
1547 while (buf2[i] != '\0') {
1548 if (buf2[i] == '\t') {
1549 ULong_t j = i+1;
1550 while (buf2[j] == 16 && buf2[j] != '\0')
1551 j++;
1552 strcpy(buf2+i+1, buf2+j);
1553 }
1554 i++;
1555 }
1556
1557 const UInt_t len = sizeof(char)*(strlen(buf2)+1);
1558
1559 const size_t ret = fwrite(buf2, len, 1, p);
1560 delete [] buf1;
1561 delete [] buf2;
1562
1563 if (ret!=1)
1564 {
1565 *fLog << err << "ERROR - fwrite to pipe " << pipe << " failed: " << strerror(errno) << endl;
1566 rc = kFALSE;
1567 break;
1568 }
1569
1570 pos.fY++;
1571 }
1572 gSystem->ClosePipe(p);
1573 return kTRUE;
1574}
1575
1576// --------------------------------------------------------------------------
1577//
1578// Print the log text.
1579//
1580// The default command line c is: a2ps -P%p
1581// %p: printer name
1582//
1583// The default printer name p is: <empty>
1584//
1585// Both can be changed in .rootrc by:
1586// PrintText.Printer
1587// PrintText.Command
1588//
1589Bool_t MStatusDisplay::PrintLog(const char *p, const char *c)
1590{
1591 static TString sprinter = gEnv->GetValue("PrintText.Printer", p&&*p?p:"");
1592 static TString scmd = gEnv->GetValue("PrintText.Command", c&&*c?c:"a2ps -P%p");
1593
1594 TString tmp;
1595 TString cmd = PrintDialog(sprinter, scmd, tmp);
1596 if (cmd.IsNull())
1597 return kFALSE;
1598
1599 // set status lines
1600 SetStatusLine1("Printing...");
1601 SetStatusLine2("");
1602
1603 // print to temporary file
1604 if (!SaveLogAsPS(cmd))
1605 {
1606 *fLog << warn << "MStatusDisplay::PrintLog: Sorry, couldn't create postscript!" << endl;
1607 SetStatusLine2("Failed!");
1608 return kFALSE;
1609 }
1610
1611 // execute command
1612 *fLog << dbg << "Executing: " << cmd << endl;
1613 gSystem->Exec(cmd);
1614
1615 SetStatusLine2("Done.");
1616
1617 return kTRUE;
1618}
1619
1620// --------------------------------------------------------------------------
1621//
1622// Process the kC_COMMAND, kCM_MENU messages
1623//
1624Bool_t MStatusDisplay::ProcessMessageCommandMenu(Long_t id)
1625{
1626 switch (id)
1627 {
1628 case kLoopPause:
1629 {
1630 TGPopupMenu *m = GetPopup("Loop");
1631 if (!m)
1632 return kTRUE;
1633
1634 if (fStatus==kLoopNone)
1635 {
1636 fStatus = (Status_t)kLoopPause;
1637 m->CheckEntry(kLoopPause);
1638 m->EnableEntry(kLoopStep);
1639 return kTRUE;
1640 }
1641 if (fStatus==kLoopPause)
1642 {
1643 fStatus = (Status_t)kLoopNone;
1644 m->UnCheckEntry(kLoopPause);
1645 m->DisableEntry(kLoopStep);
1646 return kTRUE;
1647 }
1648 }
1649 return kTRUE;
1650
1651 case kLoopStep:
1652 fStatus = (Status_t)kLoopStep;
1653 return kTRUE;
1654
1655 case kLoopStop:
1656 case kFileClose:
1657 case kFileExit:
1658 if (id==kFileExit || id==kFileClose)
1659 if (Close())
1660 delete this;
1661 fStatus = (Status_t)id;
1662 return kTRUE;
1663
1664 case kFileCanvas:
1665 new TCanvas;
1666 return kTRUE;
1667
1668 case kFileBrowser:
1669 new TBrowser;
1670 return kTRUE;
1671
1672 case kFileTab:
1673 AddTab(MString::Format("%d", fTab->GetNumberOfTabs()));
1674 return kTRUE;
1675
1676 case kFileReset:
1677 Reset();
1678 return kTRUE;
1679
1680 case kFileOpen:
1681 Open();
1682 return kTRUE;
1683
1684 case kFileSaveAs:
1685 SaveAs();
1686 return kTRUE;
1687
1688 case kFileSaveAsPS:
1689 SaveAsPS();
1690 return kTRUE;
1691
1692 case kFileSaveAsPDF:
1693 SaveAsPDF();
1694 return kTRUE;
1695
1696 case kFileSaveAsSVG:
1697 SaveAsSVG();
1698 return kTRUE;
1699
1700 case kFileSaveAsPNG:
1701 SaveAsPNG();
1702 return kTRUE;
1703
1704 case kFileSaveAsGIF:
1705 SaveAsGIF();
1706 return kTRUE;
1707
1708 case kFileSaveAsXPM:
1709 SaveAsXPM();
1710 return kTRUE;
1711
1712 case kFileSaveAsJPG:
1713 SaveAsJPG();
1714 return kTRUE;
1715
1716 case kFileSaveAsTIFF:
1717 SaveAsTIFF();
1718 return kTRUE;
1719
1720 case kFileSaveAsBMP:
1721 SaveAsBMP();
1722 return kTRUE;
1723
1724 case kFileSaveAsXML:
1725 SaveAsXML();
1726 return kTRUE;
1727
1728 case kFileSaveAsCSV:
1729 SaveAsCSV();
1730 return kTRUE;
1731
1732 case kFileSaveAsC:
1733 SaveAsC();
1734 return kTRUE;
1735
1736 case kFileSaveAsRoot:
1737 SaveAsRoot();
1738 return kTRUE;
1739
1740 case kFileSaveAsPlainRoot:
1741 SaveAsPlainRoot(kTRUE);
1742 return kTRUE;
1743
1744 case kFilePrint:
1745 PrintPS();
1746 return kTRUE;
1747
1748 case kTabSaveAs:
1749 SaveAs(fTab->GetCurrent());
1750 return kTRUE;
1751
1752 case kTabSaveAsPS:
1753 SaveAsPS(fTab->GetCurrent());
1754 return kTRUE;
1755
1756 case kTabSaveAsPDF:
1757 SaveAsPDF(fTab->GetCurrent());
1758 return kTRUE;
1759
1760 case kTabSaveAsSVG:
1761 SaveAsSVG(fTab->GetCurrent());
1762 return kTRUE;
1763
1764 case kTabSaveAsPNG:
1765 SaveAsPNG(fTab->GetCurrent());
1766 return kTRUE;
1767
1768 case kTabSaveAsGIF:
1769 SaveAsGIF(fTab->GetCurrent());
1770 return kTRUE;
1771
1772 case kTabSaveAsXPM:
1773 SaveAsXPM(fTab->GetCurrent());
1774 return kTRUE;
1775
1776 case kTabSaveAsJPG:
1777 SaveAsJPG(fTab->GetCurrent());
1778 return kTRUE;
1779
1780 case kTabSaveAsTIFF:
1781 SaveAsTIFF(fTab->GetCurrent());
1782 return kTRUE;
1783
1784 case kTabSaveAsBMP:
1785 SaveAsBMP(fTab->GetCurrent());
1786 return kTRUE;
1787
1788 case kTabSaveAsXML:
1789 SaveAsXML(fTab->GetCurrent());
1790 return kTRUE;
1791
1792 case kTabSaveAsCSV:
1793 SaveAsCSV(fTab->GetCurrent());
1794 return kTRUE;
1795
1796 case kTabSaveAsC:
1797 SaveAsC(fTab->GetCurrent());
1798 return kTRUE;
1799
1800 case kTabSaveAsPlainRoot:
1801 SaveAsPlainRoot(fTab->GetCurrent());
1802 return kTRUE;
1803
1804 case kTabSaveAsRoot:
1805 SaveAsRoot(fTab->GetCurrent());
1806 return kTRUE;
1807
1808 case kTabPrint:
1809 PrintPS(fTab->GetCurrent());
1810 return kTRUE;
1811
1812 case kTabNext:
1813 fTab->SetTab(fTab->GetCurrent()+1);
1814 return kTRUE;
1815
1816 case kTabPrevious:
1817 fTab->SetTab(fTab->GetCurrent()-1);
1818 return kTRUE;
1819
1820 case kTabRemove:
1821 RemoveTab(fTab->GetCurrent());
1822 return kTRUE;
1823
1824 case kSize640:
1825 SetDisplaySize(640, 480);
1826 return kTRUE;
1827 case kSize768:
1828 SetDisplaySize(768, 576);
1829 return kTRUE;
1830 case kSize800:
1831 SetDisplaySize(800, 600);
1832 return kTRUE;
1833 case kSize960:
1834 SetDisplaySize(960, 720);
1835 return kTRUE;
1836 case kSize1024:
1837 SetDisplaySize(1024, 768);
1838 return kTRUE;
1839 case kSize1152:
1840 SetDisplaySize(1152, 864);
1841 return kTRUE;
1842 case kSize1280:
1843 SetDisplaySize(1280, 1024);
1844 return kTRUE;
1845 case kSize1400:
1846 SetDisplaySize(1400, 1050);
1847 return kTRUE;
1848 case kSize1600:
1849 SetDisplaySize(1600, 1200);
1850 return kTRUE;
1851 case kSizeOptimum:
1852 SetOptimumSize();
1853 return kTRUE;
1854
1855 case kLogClear:
1856 fLogBox->Clear();
1857 return kTRUE;
1858 case kLogCopy:
1859 fLogBox->Copy();
1860 return kTRUE;
1861 case kLogSelect:
1862 fLogBox->SelectAll();
1863 return kTRUE;
1864 case kLogFind:
1865 new MSearch(this);
1866 return kTRUE;
1867 case kLogSave:
1868 SetStatusLine1("Saving log...");
1869 SetStatusLine2("");
1870 *fLog << inf << "Saving log... " << flush;
1871 if (fLogBox->GetText()->Save(MString::Format("%s.log", gROOT->GetName())))
1872 {
1873 *fLog << "done." << endl;
1874 SetStatusLine2("done.");
1875 }
1876 else
1877 {
1878 *fLog << "failed!" << endl;
1879 SetStatusLine2("Failed!");
1880 }
1881 return kTRUE;
1882
1883 case kLogAppend:
1884 SetStatusLine1("Appending log...");
1885 SetStatusLine2("");
1886 *fLog << inf << "Appending log... " << flush;
1887 if (fLogBox->GetText()->Append(MString::Format("%s.log", gROOT->GetName())))
1888 {
1889 *fLog << "done." << endl;
1890 SetStatusLine2("done.");
1891 }
1892 else
1893 {
1894 *fLog << "failed!" << endl;
1895 SetStatusLine2("Failed!");
1896 }
1897 return kTRUE;
1898
1899 case kLogPrint:
1900 PrintLog();
1901 return kTRUE;
1902#ifdef DEBUG
1903 default:
1904 cout << "Command-Menu #" << id << endl;
1905#endif
1906 }
1907 return kTRUE;
1908
1909}
1910
1911// --------------------------------------------------------------------------
1912//
1913// Process the kC_COMMAND messages
1914//
1915Bool_t MStatusDisplay::ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2)
1916{
1917 switch (submsg)
1918 {
1919 case kCM_MENU: // 1
1920 return ProcessMessageCommandMenu(mp1); // mp2=userdata
1921 case kCM_TAB: // 8
1922 /*
1923 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
1924 fTab->GetTabContainer(i)->UnmapWindow();
1925 */
1926 UpdateTab(fTab->GetTabContainer(mp1));
1927 //fTab->GetTabContainer(mp1)->MapWindow();
1928
1929 /*
1930 if (mp1>0)
1931 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1932 else
1933 fMenu->RemovePopup("CaOs");
1934 fMenu->Resize(fMenu->GetDefaultSize());
1935 MapSubwindows();
1936 MapWindow();
1937 */
1938 return kTRUE;
1939 case kCM_COMBOBOX: // 7
1940 if (mp1==kTabs)
1941 fTab->SetTab(mp2);
1942 return kTRUE;
1943#ifdef DEBUG
1944 case kCM_MENUSELECT: // 2
1945 cout << "Command-Menuselect #" << mp1 << " (UserData=" << (void*)mp2 << ")" << endl;
1946 return kTRUE;
1947
1948 case kCM_BUTTON: // 3
1949 cout << "Command-Button." << endl;
1950 return kTRUE;
1951
1952 case kCM_CHECKBUTTON: // 4
1953 cout << "Command-CheckButton." << endl;
1954 return kTRUE;
1955
1956 case kCM_RADIOBUTTON: // 5
1957 cout << "Command-RadioButton." << endl;
1958 return kTRUE;
1959
1960 case kCM_LISTBOX: // 6
1961 cout << "Command-Listbox #" << mp1 << " (LineId #" << mp2 << ")" << endl;
1962 return kTRUE;
1963 default:
1964 cout << "Command: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1965#endif
1966 }
1967 return kTRUE;
1968}
1969
1970// --------------------------------------------------------------------------
1971//
1972// Process the kC_TEXTVIEW messages
1973//
1974Bool_t MStatusDisplay::ProcessMessageTextview(Long_t /*submsg*/, Long_t /*mp1*/, Long_t /*mp2*/)
1975{
1976 // kC_TEXTVIEW, kTXT_ISMARKED, widget id, [true|false] //
1977 // kC_TEXTVIEW, kTXT_DATACHANGE, widget id, 0 //
1978 // kC_TEXTVIEW, kTXT_CLICK2, widget id, position (y << 16) | x) //
1979 // kC_TEXTVIEW, kTXT_CLICK3, widget id, position (y << 16) | x) //
1980 // kC_TEXTVIEW, kTXT_F3, widget id, true //
1981 // kC_TEXTVIEW, kTXT_OPEN, widget id, 0 //
1982 // kC_TEXTVIEW, kTXT_CLOSE, widget id, 0 //
1983 // kC_TEXTVIEW, kTXT_SAVE, widget id, 0 //
1984#ifdef DEBUG
1985 switch (submsg)
1986 {
1987 case kTXT_ISMARKED:
1988 cout << "Textview-IsMarked #" << mp1 << " " << (mp2?"yes":"no") << endl;
1989 return kTRUE;
1990
1991 case kTXT_DATACHANGE:
1992 cout << "Textview-DataChange #" << mp1 << endl;
1993 return kTRUE;
1994
1995 case kTXT_CLICK2:
1996 cout << "Textview-Click2 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
1997 return kTRUE;
1998
1999 case kTXT_CLICK3:
2000 cout << "Textview-Click3 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
2001 return kTRUE;
2002
2003 case kTXT_F3:
2004 cout << "Textview-F3 #" << mp1 << endl;
2005 return kTRUE;
2006
2007 case kTXT_OPEN:
2008 cout << "Textview-Open #" << mp1 << endl;
2009 return kTRUE;
2010
2011 case kTXT_CLOSE:
2012 cout << "Textview-Close #" << mp1 << endl;
2013 return kTRUE;
2014
2015 case kTXT_SAVE:
2016 cout << "Textview-Save #" << mp1 << endl;
2017 return kTRUE;
2018
2019 default:
2020 cout << "Textview: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2021 }
2022#endif
2023 return kTRUE;
2024}
2025
2026// --------------------------------------------------------------------------
2027//
2028// Process the kC_USER messages
2029//
2030Bool_t MStatusDisplay::ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2)
2031{
2032 // kS_START, case sensitive | backward<<1, char *txt
2033 switch (submsg)
2034 {
2035 case kS_START:
2036 fLogBox->Search((char*)mp2, !(mp1&2>>1), mp1&1);
2037 return kTRUE;
2038#ifdef DEBUG
2039 default:
2040 cout << "User: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2041#endif
2042 }
2043 return kTRUE;
2044}
2045
2046// --------------------------------------------------------------------------
2047//
2048// Process the messages from the GUI
2049//
2050Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
2051{
2052 // Can be found in WidgetMessageTypes.h
2053#ifdef DEBUG
2054 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
2055 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2056#endif
2057 switch (GET_MSG(msg))
2058 {
2059 case kC_COMMAND: // 1
2060 return ProcessMessageCommand(GET_SUBMSG(msg), mp1, mp2);
2061
2062 case kC_TEXTVIEW: // 9
2063 return ProcessMessageTextview(GET_SUBMSG(msg), mp1, mp2);
2064
2065 case kC_USER: // 1001
2066 return ProcessMessageUser(GET_SUBMSG(msg), mp1, mp2);
2067 }
2068#ifdef DEBUG
2069 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
2070 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2071#endif
2072 return kTRUE;
2073}
2074
2075Bool_t MStatusDisplay::Close()
2076{
2077 // Got close message for this MainFrame. Calls parent CloseWindow()
2078 // (which destroys the window) and terminate the application.
2079 // The close message is generated by the window manager when its close
2080 // window menu item is selected.
2081
2082 // CloseWindow must be overwritten because otherwise CloseWindow
2083 // and the destructor are calling DestroyWindow which seems to be
2084 // in conflict with the TRootEmbeddedCanvas.
2085
2086 // FIXME: Make sure that the Status Display is deleted from every
2087 // where (eg Eventloop) first!
2088
2089 //gLog << dbg << fName << " is on heap: " << (int)IsOnHeap() << endl;
2090
2091 if (TestBit(kExitLoopOnExit) || TestBit(kExitLoopOnClose))
2092 {
2093 //gLog << dbg << "CloseWindow() calling ExitLoop." << endl;
2094 gSystem->ExitLoop();
2095 }
2096
2097 if (fIsLocked<=0 && IsOnHeap())
2098 return kTRUE;
2099
2100 fStatus = kFileExit;
2101 return kFALSE;
2102}
2103
2104void MStatusDisplay::CloseWindow()
2105{
2106 if (Close())
2107 delete this;
2108}
2109
2110// --------------------------------------------------------------------------
2111//
2112// Calls SetBit(kNoContextMenu) for all TCanvas objects found in the
2113// Tabs.
2114//
2115void MStatusDisplay::SetNoContextMenu(Bool_t flag)
2116{
2117 if (fIsLocked>1 || gROOT->IsBatch())
2118 return;
2119
2120 flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
2121
2122 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
2123 {
2124 TCanvas *c = GetCanvas(i);
2125 if (c)
2126 flag ? c->SetBit(kNoContextMenu) : c->ResetBit(kNoContextMenu);
2127 }
2128}
2129
2130// --------------------------------------------------------------------------
2131//
2132// Update the memory display in the status bar
2133//
2134void MStatusDisplay::UpdateMemory() const
2135{
2136 const TString path = MString::Format("/proc/%d/status", gSystem->GetPid());
2137 if (gSystem->AccessPathName(path, kFileExists))
2138 return;
2139
2140 TEnv env(path);
2141 const UInt_t kb = env.GetValue("VmSize", 0);
2142 if (kb==0)
2143 return;
2144
2145 char type = 'k';
2146 Float_t val = kb;
2147
2148 if (val>999)
2149 {
2150 type = 'M';
2151 val /= 1000;
2152 }
2153 if (val>999)
2154 {
2155 type = 'G';
2156 val /= 1000;
2157 }
2158 const TString txt = MString::Format("%.1f%c", val, type);
2159 fStatusBar->SetText(txt, 2);
2160}
2161
2162// --------------------------------------------------------------------------
2163//
2164// Updates the canvas (if existing) in the currenly displayed Tab.
2165// The update intervall is controlled by StartUpdate and StopUpdate
2166//
2167Bool_t MStatusDisplay::HandleTimer(TTimer *timer)
2168{
2169 if (gROOT->IsBatch())
2170 return kTRUE;
2171
2172 UpdateMemory();
2173
2174 const Int_t c = fTab->GetCurrent();
2175
2176 // Skip Legend Tab
2177 if (c==0)
2178 return kTRUE;
2179
2180 // Update a canvas tab (if visible)
2181 if (timer==&fTimer && c!=fLogIdx)
2182 {
2183 UpdateTab(fTab->GetCurrentContainer());
2184 return kTRUE;
2185 }
2186
2187 // update the logbook tab (if visible)
2188 if (timer==&fLogTimer && c==fLogIdx)
2189 {
2190 fLog->UpdateGui();
2191
2192 /*
2193 if (!fLogBox->TestBit(kHasChanged))
2194 return kTRUE;
2195
2196 fLogBox->ResetBit(kHasChanged);
2197 */
2198 return kTRUE;
2199 }
2200
2201 return kTRUE;
2202}
2203
2204// --------------------------------------------------------------------------
2205//
2206// Find an object in a canvas (uses MStatusArray as helper)
2207//
2208void MStatusDisplay::PrintContent(Option_t *o) const
2209{
2210 MStatusArray(*this).Print(o);
2211}
2212
2213// --------------------------------------------------------------------------
2214//
2215// Find an object in a canvas (uses MStatusArray as helper)
2216//
2217TObject *MStatusDisplay::FindObjectInCanvas(const char *obj, const char *base, const char *canv) const
2218{
2219 return MStatusArray(*this).FindObjectInCanvas(obj, base, canv);
2220}
2221
2222// --------------------------------------------------------------------------
2223//
2224// Draws a clone of a canvas into a new canvas. Taken from TCanvas.
2225//
2226void MStatusDisplay::DrawClonePad(TCanvas &newc, TCanvas &oldc) const
2227{
2228 //copy pad attributes
2229 newc.Range(oldc.GetX1(),oldc.GetY1(),oldc.GetX2(),oldc.GetY2());
2230 newc.SetTickx(oldc.GetTickx());
2231 newc.SetTicky(oldc.GetTicky());
2232 newc.SetGridx(oldc.GetGridx());
2233 newc.SetGridy(oldc.GetGridy());
2234 newc.SetLogx(oldc.GetLogx());
2235 newc.SetLogy(oldc.GetLogy());
2236 newc.SetLogz(oldc.GetLogz());
2237 newc.SetBorderSize(oldc.GetBorderSize());
2238 newc.SetBorderMode(oldc.GetBorderMode());
2239 ((TAttLine&)oldc).Copy((TAttLine&)newc);
2240 ((TAttFill&)oldc).Copy((TAttFill&)newc);
2241 ((TAttPad&)oldc).Copy((TAttPad&)newc);
2242
2243 // This must be there: Otherwise GetDrawOption() won't work
2244 TVirtualPad *padsav = gPad;
2245 oldc.cd();
2246
2247 const Bool_t store = TH1::AddDirectoryStatus();
2248 TH1::AddDirectory(kFALSE);
2249
2250 //copy primitives
2251 TObject *obj;
2252 TIter next(oldc.GetListOfPrimitives());
2253 while ((obj=next()))
2254 {
2255 // Old line - I think it is not necessary anymore because of the cd()
2256 //gROOT->SetSelectedPad(&newc);
2257
2258 // Now make a clone of the object
2259 TObject *clone = obj->Clone();
2260
2261 // Clone also important bits (FIXME: Is this correct)
2262 clone->SetBit(obj->TestBits(kCannotPick|kNoContextMenu));
2263
2264 // Now make sure that the clones are deleted at a later time
2265 clone->SetBit(kCanDelete|kMustCleanup);
2266
2267 // FIXME: This is a workaround for the problem with the MAstroCatalog in
2268 // MHFalseSource. It doesn't harm. We'll still try to find the reason
2269 //if (clone->IsA()==TPad::Class())
2270 // gROOT->GetListOfCleanups()->Add(clone);
2271
2272 // Add the clone and its draw-option to the current pad
2273 TVirtualPad *save2 = gPad;
2274 gPad = &oldc; // Don't do this before Clone()!
2275 newc.GetListOfPrimitives()->Add(clone, obj->GetDrawOption());
2276 gPad = save2;
2277 }
2278 newc.Modified();
2279 newc.Update();
2280
2281 TH1::AddDirectory(store);
2282
2283 padsav->cd();
2284}
2285
2286// --------------------------------------------------------------------------
2287//
2288// Display the contexts of a TObjArray in the display (all canvases)
2289//
2290Bool_t MStatusDisplay::Display(const TObjArray &list, const char *tab)
2291{
2292 TIter Next(&list);
2293
2294 TObject *o=Next();
2295 if (!o)
2296 {
2297 *fLog << err << "MStatusDisplay::Display: No entry in TObjArray." << endl;
2298 return kFALSE;
2299 }
2300
2301 // The first entry in the list is a TNamed which is expected to
2302 // contain the status display title.
2303 fTitle = o->GetTitle();
2304
2305 TCanvas *c;
2306 while ((c=(TCanvas*)Next()))
2307 //if (!GetCanvas(c->GetName()))
2308 if (c->InheritsFrom(TCanvas::Class()))
2309 if (!tab || c->GetName()==(TString)tab)
2310 DrawClonePad(AddTab(c->GetName(), c->GetTitle()), *c);
2311
2312 return kTRUE;
2313}
2314
2315// --------------------------------------------------------------------------
2316//
2317// Reads the contents of a saved MStatusDisplay from a file.
2318//
2319Int_t MStatusDisplay::Read(const char *name, const char *tab)
2320{
2321 if (!gFile)
2322 {
2323 *fLog << warn << "MStatusDisplay::Read: No file found. Please create a TFile first." << endl;
2324 return 0;
2325 }
2326
2327 if (!gFile->IsOpen())
2328 {
2329 *fLog << warn << "MStatusDisplay::Read: File not open. Please open the TFile first." << endl;
2330 return 0;
2331 }
2332
2333 MStatusArray list;
2334
2335 const Int_t n = list.Read(name);
2336
2337 //
2338 // If no status display was found with this name try to find canvases
2339 // in the file and display them instead.
2340 //
2341 if (n==0)
2342 {
2343 // Either read the title from the file or create our own
2344 TNamed *n=0;
2345 gFile->GetObject("Title", n); // FIXME: Is the list allowed to take ownership?
2346 list.Add(n ? n : new TNamed(GetName(), GetTitle()));
2347
2348 const Bool_t store = TH1::AddDirectoryStatus();
2349 TH1::AddDirectory(kFALSE);
2350
2351 TIter Next(gFile->GetListOfKeys());
2352 TObject *key = 0;
2353 while ((key=Next()))
2354 {
2355 MStatusArray *arr=0;
2356 gFile->GetObject(key->GetName(), arr);
2357 if (arr)
2358 {
2359 Display(*arr, tab);
2360 n++;
2361 continue;
2362 }
2363
2364 if (tab && key->GetName()!=(TString)tab)
2365 continue;
2366
2367 TCanvas *c=0;
2368 gFile->GetObject(key->GetName(), c);
2369
2370 // If key doesn't correspond to a TCanvas create a new canvas
2371 // and draw the object itself instead.
2372 if (!c)
2373 {
2374 TObject *obj = gFile->Get(key->GetName());
2375
2376 if (MParContainer::Overwrites(TObject::Class(), *obj, "Draw") ||
2377 MParContainer::Overwrites(TObject::Class(), *obj, "Paint"))
2378 {
2379 AddTab(key->GetName(), key->GetTitle());
2380 obj->SetBit(kCanDelete);
2381 obj->Draw();
2382 }
2383 // FIXME: Is the object deleted?
2384 continue;
2385 }
2386
2387 // Add the canvas to the list
2388 const TString name = c->GetName();
2389 const TString title = c->GetTitle();
2390 if (title.IsNull() || name==title)
2391 c->SetTitle(gFile->GetName());
2392 list.Add(c);
2393 }
2394
2395 TH1::AddDirectory(store);
2396
2397 if (list.GetEntries()<=1)
2398 {
2399 *fLog << warn << "MStatusDisplay::Read: No drawable objects read from " << gFile->GetName() << endl;
2400 return 0;
2401 }
2402
2403 *fLog << inf << "MStatusDisplay: " << list.GetEntries()-1 << " canvases directly read from file." << endl;
2404 }
2405
2406
2407 if (!Display(list, tab))
2408 {
2409 *fLog << err << "MStatusDisplay::Display: No entries found." << endl;
2410 return 0;
2411 }
2412
2413 if (n==0)
2414 return list.GetEntries();
2415
2416 *fLog << inf << "MStatusDisplay: Key " << name << " with " << n << " keys read from file." << endl;
2417 return n;
2418}
2419
2420// --------------------------------------------------------------------------
2421//
2422// Add all canvases to the MStatusArray
2423//
2424void MStatusDisplay::FillArray(MStatusArray &list, Int_t num) const
2425{
2426 Int_t from, to;
2427 GetCanvasRange(from, to, num);
2428
2429 TCanvas *c;
2430 for (int i=from; i<to; i++)
2431 if ((c = GetCanvas(i)))
2432 list.Add(c);
2433}
2434
2435// --------------------------------------------------------------------------
2436//
2437// Writes the contents of a MStatusDisplay to a file.
2438//
2439Int_t MStatusDisplay::Write(Int_t num, const char *name, Option_t *opt) const
2440{
2441 if (!gFile)
2442 {
2443 *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
2444 return 0;
2445 }
2446
2447 if (!gFile->IsOpen())
2448 {
2449 *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
2450 return 0;
2451 }
2452
2453 if (!gFile->IsWritable())
2454 {
2455 *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
2456 return 0;
2457 }
2458
2459 if (num==0)
2460 {
2461 *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
2462 return 0;
2463 }
2464
2465 if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
2466 {
2467 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
2468 return 0;
2469 }
2470 if (gROOT->IsBatch() && num>fBatch->GetSize())
2471 {
2472 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
2473 return 0;
2474 }
2475
2476 Int_t n = 0; // Number of keys written
2477
2478 TNamed named("Title", fTitle.Data());
2479
2480 if (TString(opt)=="plain")
2481 {
2482 // Get canvas range to store
2483 Int_t from, to;
2484 GetCanvasRange(from, to, num);
2485
2486 n += named.Write();
2487
2488 TCanvas *c;
2489 for (int i=from; i<to; i++)
2490 if ((c = GetCanvas(i)))
2491 n += c->Write();
2492 }
2493 else
2494 {
2495 // Be careful: So far Display() assumes that the TNamed
2496 // is the first entry in the list
2497 MStatusArray list;
2498 list.Add(&named);
2499
2500 FillArray(list, num);
2501
2502 n += list.Write(name, kSingleKey);
2503 }
2504
2505 *fLog << inf << "MStatusDisplay: " << n << " keys written to file as key " << name << "." << endl;
2506
2507 return n;
2508}
2509
2510// --------------------------------------------------------------------------
2511//
2512// Use this to start the synchronous (GUI eventloop driven) tab update.
2513// Can also be used to change the update intervall. If millisec<0
2514// the intervall given in SetUpdateTime is used. If the intervall in
2515// SetUpdateTime is <0 nothing is done. (Call SetUpdateTime(-1) to
2516// disable the automatic update in a MEventloop.
2517//
2518void MStatusDisplay::StartUpdate(Int_t millisec)
2519{
2520 if (fIsLocked>1)
2521 return;
2522
2523 if (fTimer.GetTime()<TTime(0))
2524 return;
2525 fTimer.Start(millisec);
2526}
2527
2528// --------------------------------------------------------------------------
2529//
2530// Stops the automatic GUI update
2531//
2532void MStatusDisplay::StopUpdate()
2533{
2534 if (fIsLocked>1)
2535 return;
2536
2537 fTimer.Stop();
2538}
2539
2540// --------------------------------------------------------------------------
2541//
2542// Set the update interval for the GUI update, see StartUpdate.
2543//
2544void MStatusDisplay::SetUpdateTime(Long_t t)
2545{
2546 fTimer.SetTime(t);
2547}
2548
2549// --------------------------------------------------------------------------
2550//
2551// If the filename name doesn't end with ext, ext is added to the end.
2552// If name.IsNull() "status" is assumed and the a number (>0) is added
2553// as "status-6".
2554// The extension is returned.
2555//
2556const TString &MStatusDisplay::AddExtension(TString &name, const TString &ext, Int_t num) const
2557{
2558 if (name.IsNull())
2559 {
2560 name = gROOT->GetName();
2561 if (num>0)
2562 {
2563 name += "-";
2564 name += num;
2565 }
2566 }
2567
2568 if (name.EndsWith("."+ext))
2569 return ext;
2570
2571 name += ".";
2572 name += ext;
2573
2574 return ext;
2575}
2576
2577Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
2578{
2579 if (gROOT->IsBatch())
2580 return (num>0 && num<=fBatch->GetSize()) || num<0;
2581
2582 if (num>=fTab->GetNumberOfTabs())
2583 {
2584 *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
2585 return kFALSE;
2586 }
2587 if (num==0)
2588 {
2589 *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
2590 return kFALSE;
2591 }
2592 if (fTab->GetNumberOfTabs()<2 || !gPad)
2593 {
2594 *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
2595 return kFALSE;
2596 }
2597 return kTRUE;
2598}
2599
2600// --------------------------------------------------------------------------
2601//
2602// Insert the following two lines into the postscript header:
2603//
2604// %%DocumentPaperSizes: a4
2605// %%Orientation: Landscape
2606//
2607void MStatusDisplay::UpdatePSHeader(const TString &name) const
2608{
2609 const TString newstr("%%DocumentPaperSizes: a4\n%%Orientation: Landscape\n");
2610
2611 TString tmp(name+"XXXXXX");
2612
2613 // FIXME: Use mkstemp instead
2614 if (!mktemp(const_cast<char*>(tmp.Data())))
2615 {
2616 *fLog << err << "ERROR - MStatusDisplay::UpdatePSHeader: mktemp failed." << endl;
2617 return;
2618 }
2619
2620 ifstream fin(name);
2621 ofstream fout(tmp);
2622 if (!fout)
2623 {
2624 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
2625 return;
2626 }
2627
2628 char c;
2629
2630 TString str;
2631 fin >> str >> c; // Read "%!PS-Adobe-2.0\n"
2632 fout << str << endl << newstr;
2633
2634 // Doing it in blocks seems not to gain much for small (MB) files
2635 while (fin)
2636 {
2637 fin.read(&c, 1);
2638 fout.write(&c, 1);
2639 }
2640
2641 gSystem->Unlink(name);
2642 gSystem->Rename(tmp, name);
2643}
2644
2645// --------------------------------------------------------------------------
2646//
2647void MStatusDisplay::PSToolsRange(TVirtualPS &vps, Float_t psw, Float_t psh) const
2648{
2649 if (vps.InheritsFrom(TPostScript::Class()))
2650 static_cast<TPostScript&>(vps).Range(psw, psh);
2651 // if (vps.InheritsFrom(TPDF::Class()))
2652 // static_cast<TPDF&>(vps).Range(psw*0.69, psh*0.69);
2653 // if (vps.InheritsFrom(TSVG::Class()))
2654 // static_cast<TSVG&>(vps).Range(psw, psh);
2655}
2656
2657// --------------------------------------------------------------------------
2658//
2659void MStatusDisplay::PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const
2660{
2661 if (vps.InheritsFrom(TPostScript::Class()))
2662 static_cast<TPostScript&>(vps).TextNDC(u, v, string);
2663 if (vps.InheritsFrom(TPDF::Class()))
2664 static_cast<TPDF&>(vps).TextNDC(u, v, string);
2665 // if (vps.InheritsFrom(TSVG::Class()))
2666 // static_cast<TSVG&>(vps).TextNDC(u, v, string);
2667}
2668
2669// --------------------------------------------------------------------------
2670//
2671Int_t MStatusDisplay::InitWriteDisplay(Int_t num, TString &name, const TString &ext)
2672{
2673 SetStatusLine1(MString::Format("Writing %s file...",ext.Data()));
2674 SetStatusLine2("Please be patient!");
2675
2676 if (!CheckTabForCanvas(num))
2677 {
2678 SetStatusLine2("Failed!");
2679 return 0;
2680 }
2681
2682 AddExtension(name, ext, num);
2683
2684 if (num<0)
2685 *fLog << inf << "Open " << ext << "-File: " << name << endl;
2686
2687 return num;
2688}
2689
2690// --------------------------------------------------------------------------
2691//
2692TCanvas *MStatusDisplay::InitWriteTab(Int_t num, TString &name)
2693{
2694 const Int_t i = TMath::Abs(num);
2695
2696 TCanvas *c = GetCanvas(i);
2697 if (!c)
2698 {
2699 if (num<0)
2700 *fLog << inf << " - ";
2701 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
2702 return 0;
2703 }
2704
2705 SetStatusLine2(MString::Format("Tab #%d", i));
2706
2707 //
2708 // Paint canvas into root file
2709 //
2710 if (num<0 && !name.IsNull())
2711 {
2712 Bool_t found = kFALSE;
2713 if (name.Index("%%%%name%%%%")>=0)
2714 {
2715 name.ReplaceAll("%%name%%", c->GetName());
2716 found = kTRUE;
2717 }
2718
2719 if (name.Index("%%%%title%%%%")>=0)
2720 {
2721 name.ReplaceAll("%%title%%", c->GetTitle());
2722 found = kTRUE;
2723 }
2724
2725 if (name.Index("%%%%tab%%%%")>=0)
2726 {
2727 name.ReplaceAll("%%tab%%", MString::Format("%d", i));
2728 found = kTRUE;
2729 }
2730
2731 if (!found)
2732 name.Insert(name.Last('.'), MString::Format("-%d", i));
2733 }
2734
2735 if (num<0)
2736 *fLog << inf << " - ";
2737 *fLog << inf << "Writing Tab #" << i;
2738
2739 if (!name.IsNull())
2740 *fLog << " to " << name;
2741
2742 *fLog << ": " << c->GetName() << "... " << flush;
2743
2744 return c;
2745}
2746
2747// This is a stupid workaround to get rid of the damned clipping
2748// of the text. Who the hell needs clipping?
2749class MyCanvas : public TCanvas
2750{
2751public:
2752 void Scale(Double_t val)
2753 {
2754 fAbsXlowNDC = -val;
2755 fAbsYlowNDC = -val;
2756 fAbsWNDC = 1+2*val;
2757 fAbsHNDC = 1+2*val;
2758 }
2759};
2760
2761// --------------------------------------------------------------------------
2762//
2763// Write some VGF (vector graphics format). Currently PS, PDF and SVG
2764// is available. Specified by ext.
2765//
2766// In case of num<0 all tabs are written into the VGF file. If num>0
2767// the canvas in the corresponding tab is written to the file.
2768// Name is the name of the file (with or without extension).
2769//
2770// Returns the number of pages written.
2771//
2772// To write all tabs you can also use SaveAsVGF(name, ext)
2773//
2774// If the third argument is given a bottom line is drawn with the text
2775// under it. If no argument is given a bottom line is drawn if
2776// fTitle (SetTitle) is not empty.
2777//
2778Int_t MStatusDisplay::SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext)
2779{
2780 num = InitWriteDisplay(num, name, ext);
2781 if (num==0)
2782 return 0;
2783
2784 TPad *padsav = (TPad*)gPad;
2785 TVirtualPS *psave = gVirtualPS;
2786
2787 TDatime d;
2788
2789 Int_t type = -1;
2790
2791 TVirtualPS *ps =0;
2792 if (!ext.CompareTo("ps", TString::kIgnoreCase))
2793 {
2794 gStyle->SetColorModelPS(1);
2795 ps = new TPostScript(name, 112);
2796 type = 1;
2797 }
2798 if (!ext.CompareTo("pdf", TString::kIgnoreCase))
2799 {
2800 ps = new TPDF(name, 112);
2801 type = 2;
2802 }
2803 if (!ext.CompareTo("svg", TString::kIgnoreCase))
2804 {
2805 ps = new TSVG(name, 112);
2806 type = 3;
2807 }
2808
2809 if (!ps)
2810 {
2811 *fLog << err << "Extension " << ext << " unknown..." << endl;
2812 SetStatusLine2("Failed!");
2813 return 0;
2814 }
2815
2816 ps->SetBit(TPad::kPrintingPS);
2817 if (type==1)
2818 ps->PrintFast(13, "/nan {1} def ");
2819
2820 gVirtualPS = ps;
2821
2822 //
2823 // Create some GUI elements for a page legend
2824 //
2825 TLine line;
2826
2827 int page = 1;
2828
2829 //
2830 // Maintain tab numbers
2831 //
2832 Int_t from, to;
2833 GetCanvasRange(from, to, num);
2834
2835 for (int i=from; i<to; i++)
2836 {
2837 TCanvas *c = InitWriteTab(num<0?-i:i);
2838 if (c==0)
2839 continue;
2840
2841 //
2842 // Init page and page size, make sure, that the canvas in the file
2843 // has the same Aspect Ratio than on the screen.
2844 //
2845 if (type==1 || i>from)
2846 ps->NewPage();
2847
2848 //
2849 // 28 is used here to scale the canvas into a height of 28,
2850 // such that the page title can be set above the canvas...
2851 //
2852 Float_t psw = 28.0; // A4 - width (29.7)
2853 Float_t psh = 21.0; // A4 - height (21.0)
2854
2855 const Float_t cw = c->GetWw();
2856 const Float_t ch = c->GetWh();
2857
2858 if (psw/psh>cw/ch)
2859 psw = cw/ch*psh;
2860 else
2861 psh = ch/cw*psw;
2862
2863 PSToolsRange(*ps, psw, psh);
2864
2865 //
2866 // Clone canvas and change background color and schedule for
2867 // deletion
2868 //
2869
2870 //const Bool_t store = c->IsBatch();
2871 //c->SetBatch(kTRUE);
2872 c->Paint();
2873 //c->SetBatch(store);
2874
2875 //
2876 // Change/fix the canvas coordinate system for the overlaying text.
2877 // This is necessary because root clip everything away which is
2878 // outside a predefined area, which is (0,0)/(1,1)
2879 //
2880 const Double_t height = 0.015; // Text height
2881 const Double_t off = 0.005; // Line offset from text
2882
2883 const Double_t bot = height+off;
2884 const Double_t top = 1-bot;
2885
2886 static_cast<MyCanvas*>(c)->Scale(bot);
2887
2888 // If gPad is not set to c all follwing commands will
2889 // get the wrong numbers for alignment
2890 gPad = c;
2891
2892 // Separator Lines
2893 line.PaintLineNDC(0.01, top, 0.99, top);
2894 line.PaintLineNDC(0.01, bot, 0.99, bot);
2895
2896 //
2897 // Print overlaying text (NDC = %)
2898 //
2899 // align phi col font size (11=left top)
2900 const TString txt(addon.IsNull() ? fTitle : addon);
2901
2902 // Text Attributes
2903 TAttText(11, 0, kBlack, 22, height).Copy(*ps);
2904
2905 // Text on top
2906 ps->SetTextAlign(11); // left bottom
2907 PSToolsTextNDC(*ps, 0.01, top+off, c->GetName());
2908
2909 ps->SetTextAlign(21); // cent bottom
2910 PSToolsTextNDC(*ps, 0.50, top+off, TString("MARS V"MARSVER" - Modular Analysis and Reconstruction Software - ")+d.AsString());
2911
2912 ps->SetTextAlign(31); // right bottom
2913 PSToolsTextNDC(*ps, 0.99, top+off, MString::Format("Page No.%i (%i)", page++, i));
2914
2915 // Text on bottom
2916 ps->SetTextAlign(13); // left top
2917 PSToolsTextNDC(*ps, 0.01, bot-off, c->GetTitle());
2918
2919 ps->SetTextAlign(23); // cent top
2920 PSToolsTextNDC(*ps, 0.50, bot-off, txt);
2921
2922 ps->SetTextAlign(33); // right top
2923 PSToolsTextNDC(*ps, 0.99, bot-off, MString::Format("(c) 2000-%d, Thomas Bretz", TDatime().GetYear()));
2924
2925 static_cast<MyCanvas*>(c)->Scale(0);
2926
2927 //
2928 // Finish drawing page
2929 //
2930 *fLog << "done." << endl;
2931 }
2932
2933 gPad = NULL; // Important!
2934
2935 ps->Close();
2936 delete ps;
2937
2938#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
2939 if (type==1)
2940 {
2941 SetStatusLine2("Updating header of PS file...");
2942
2943 if (num<0)
2944 *fLog << inf3 << " - Updating header of PS file... " << flush;
2945 UpdatePSHeader(name);
2946 if (num<0)
2947 *fLog << inf3 << "done." << endl;
2948 }
2949#endif
2950
2951 gVirtualPS = psave;
2952 if (padsav)
2953 padsav->cd();
2954
2955 if (num<0)
2956 *fLog << inf << "done." << endl;
2957
2958 SetStatusLine2(MString::Format("Done (%dpages)", page-1));
2959
2960 return page-1;
2961}
2962
2963// --------------------------------------------------------------------------
2964//
2965Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type)
2966{
2967#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
2968 if (gROOT->IsBatch())
2969 {
2970 *fLog << warn << "Sorry, writing image-files is not available in batch mode." << endl;
2971 return 0;
2972 }
2973#endif
2974
2975 TString ext;
2976 switch (type)
2977 {
2978 case TImage::kXpm:
2979 case TImage::kZCompressedXpm: ext = "xpm"; break;
2980 case TImage::kPng: ext = "png"; break;
2981 case TImage::kJpeg: ext = "jpg"; break;
2982 case TImage::kGif: ext = "gif"; break;
2983 case TImage::kTiff: ext = "tiff"; break;
2984 case TImage::kBmp: ext = "bmp"; break;
2985 case TImage::kXml: ext = "xml"; break;
2986 //case TImage::kGZCompressedXpm: ext = "xpm.gz"; break;
2987 //case TImage::kPpm: ext = "ppm"; break;
2988 //case TImage::kPnm: ext = "pnm"; break;
2989 //case TImage::kIco: ext = "ico"; break;
2990 //case TImage::kCur: ext = "cur"; break;
2991 //case TImage::kXcf: ext = "xcf"; break;
2992 //case TImage::kXbm: ext = "xbm"; break;
2993 //case TImage::kFits: ext = "fits"; break;
2994 //case TImage::kTga: ext = "tga"; break;
2995 default:
2996 *fLog << warn << "Sorry, unknown or unsupported file type..." << endl;
2997 return 0;
2998 }
2999
3000 num = InitWriteDisplay(num, name, ext);
3001 if (num==0)
3002 return 0;
3003
3004 TPad *padsav = (TPad*)gPad;
3005
3006 Int_t counter = 0;
3007
3008 //
3009 // Maintain tab numbers
3010 //
3011 Int_t from, to;
3012 GetCanvasRange(from, to, num);
3013
3014 for (int i=from; i<to; i++)
3015 {
3016 TString writename(name);
3017
3018 TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
3019 if (!c)
3020 continue;
3021
3022 //
3023 // Paint canvas into root file
3024 //
3025
3026 // TImage *img = TImage::Create();
3027 // img->FromPad(c);
3028 // img->WriteImage(writename, type);
3029 // delete img;
3030
3031 // FIXME: Not all file types are supported by Print()
3032 c->Print(writename);
3033
3034 if (num<0)
3035 *fLog << "done." << endl;
3036
3037 counter++;
3038 }
3039
3040 if (padsav)
3041 padsav->cd();
3042
3043 *fLog << inf << "done." << endl;
3044
3045 SetStatusLine2("Done.");
3046
3047 return counter>0;
3048}
3049
3050// --------------------------------------------------------------------------
3051//
3052Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
3053{
3054 num = InitWriteDisplay(num, name, "C");
3055 if (num==0)
3056 return kFALSE;
3057
3058 TPad *padsav = (TPad*)gPad;
3059
3060 Int_t counter = 0;
3061
3062 //
3063 // Maintain tab numbers
3064 //
3065 Int_t from, to;
3066 GetCanvasRange(from, to, num);
3067
3068 for (int i=from; i<to; i++)
3069 {
3070 TString writename(name);
3071
3072 TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
3073 if (!c)
3074 continue;
3075
3076 //
3077 // Clone canvas and change background color and schedule for
3078 // deletion
3079 //
3080 c->SaveSource(writename, "");
3081
3082 if (num<0)
3083 *fLog << "done." << endl;
3084
3085 counter++;
3086 }
3087
3088 if (padsav)
3089 padsav->cd();
3090
3091 *fLog << inf << "done." << endl;
3092
3093 SetStatusLine2("Done.");
3094
3095 return counter>0;
3096}
3097
3098// --------------------------------------------------------------------------
3099//
3100// In case of num<0 all tabs are written into a root file. As plain
3101// TCanvas objects if plain==kTRUE otherwise in a MStatusArray. If num>0
3102// the canvas in the corresponding tab is written to the file.
3103// Name is the name of the file (with or without extension).
3104//
3105// Returns the number of keys written.
3106//
3107// To write all tabs you can also use SaveAsRoot(name)
3108//
3109Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name, Bool_t plain)
3110{
3111 num = InitWriteDisplay(num, name, "root");
3112 if (num==0)
3113 return -1;
3114
3115 TFile *fsave = gFile;
3116 TFile file(name, "RECREATE", GetTitle(), 9);
3117 const Int_t keys = Write(num, "MStatusDisplay", plain ? "plain" : "");
3118 gFile = fsave;
3119
3120 SetStatusLine2("Done.");
3121
3122 return keys;
3123}
3124
3125// --------------------------------------------------------------------------
3126//
3127Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name, Char_t delim)
3128{
3129 num = InitWriteDisplay(num, name, "csv");
3130 if (num==0)
3131 return kFALSE;
3132
3133 gSystem->ExpandPathName(name);
3134
3135 ofstream fout(name);
3136 if (!fout)
3137 {
3138 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
3139 return kFALSE;
3140 }
3141
3142 fout << 0 << delim << GetName() << delim << GetTitle() << endl;
3143
3144 Int_t from, to;
3145 GetCanvasRange(from, to, num);
3146
3147 for (int i=from; i<to; i++)
3148 {
3149 TCanvas *c;
3150 if (!(c = GetCanvas(i)))
3151 {
3152 if (num<0)
3153 *fLog << inf << " - ";
3154 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
3155 continue;
3156 }
3157
3158 fout << i << delim << c->GetName() << delim << c->GetTitle() << endl;
3159 }
3160
3161 SetStatusLine2("Done.");
3162
3163 return kTRUE;
3164}
3165
3166/*
3167Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name)
3168{
3169 num = InitWriteDisplay(num, name, "csv");
3170 if (num==0)
3171 return kFALSE;
3172
3173 gSystem->ExpandPathName(name);
3174
3175 ofstream fout(name);
3176 if (!fout)
3177 {
3178 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
3179 return kFALSE;
3180 }
3181
3182 fout << "<?xml version=\"1.0\"?>" << endl;
3183 fout << "<display name='" << GetName() << "'>" << endl;
3184 fout << " <file>" << name << "</file>" << endl;
3185 fout << " <status>" << endl;
3186 fout << " <name>" << GetName() << "</name>" << endl;
3187 fout << " <title>" << GetTitle() << "</title>" << endl;
3188 fout << " </status>" << endl;
3189 fout << " <tabs>" << endl;
3190
3191 fout << 0 << delim << GetName() << delim << GetTitle() << endl;
3192
3193 Int_t from, to;
3194 GetCanvasRange(from, to, num);
3195
3196 for (int i=from; i<to; i++)
3197 {
3198 TCanvas *c;
3199 if (!(c = GetCanvas(i)))
3200 {
3201 if (num<0)
3202 *fLog << inf << " - ";
3203 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
3204 continue;
3205 }
3206
3207 fout << " <tab index='" << i << "'>" << endl;
3208 fout << " <index>" << i << "</index>" << endl;
3209 fout << " <name>" << c->GetName() << "</name>" << endl;
3210 fout << " <title>" << c->GetName() << "</title>" << endl;
3211 fout << " </tab>" << endl;
3212 }
3213
3214 fout << " </tabs>" << endl;
3215 fout << "</display>" << endl;
3216
3217 SetStatusLine2("Done.");
3218
3219 return kTRUE;
3220}
3221*/
3222
3223// --------------------------------------------------------------------------
3224//
3225void MStatusDisplay::SaveAs(const char *c, const Option_t *o) const
3226{
3227#if ROOT_VERSION_CODE >= ROOT_VERSION(5,18,00)
3228 TGObject::SaveAs(c, o);
3229#endif
3230}
3231
3232// --------------------------------------------------------------------------
3233//
3234// Determin File type to save file as by extension. Allowed extensions are:
3235// root, ps, pdf, svg, gif, png, jpg, xpm, C
3236//
3237// returns -1 if file type is unknown. Otherwise return value of SaveAs*
3238//
3239Int_t MStatusDisplay::SaveAs(Int_t num, TString name)
3240{
3241 if (name.EndsWith(".root")) return SaveAsRoot(num, name); // kFileSaveAsRoot
3242 if (name.EndsWith(".ps")) return SaveAsPS(num, name); // kFileSaveAsPS
3243 if (name.EndsWith(".pdf")) return SaveAsPDF(num, name); // kFileSaveAsPDF
3244 if (name.EndsWith(".svg")) return SaveAsSVG(num, name); // kFileSaveAsSVG
3245 if (name.EndsWith(".gif")) return SaveAsGIF(num, name); // kFileSaveAsGIF
3246 if (name.EndsWith(".png")) return SaveAsPNG(num, name); // kFileSaveAsPNG
3247 if (name.EndsWith(".bmp")) return SaveAsBMP(num, name); // kFileSaveAsBMP
3248 if (name.EndsWith(".xml")) return SaveAsXML(num, name); // kFileSaveAsXML
3249 if (name.EndsWith(".jpg")) return SaveAsJPG(num, name); // kFileSaveAsJPG
3250 if (name.EndsWith(".xpm")) return SaveAsXPM(num, name); // kFileSaveAsXPM
3251 if (name.EndsWith(".csv")) return SaveAsCSV(num, name); // kFileSaveAsCSV
3252 if (name.EndsWith(".tiff")) return SaveAsTIFF(num, name); // kFileSaveAsTIFF
3253 if (name.EndsWith(".C")) return SaveAsC(num, name); // kFileSaveAsC
3254 return -1;
3255}
3256
3257// --------------------------------------------------------------------------
3258//
3259// Opens a save as dialog
3260//
3261Int_t MStatusDisplay::SaveAs(Int_t num)
3262{
3263 static const char *gSaveAsTypes[] =
3264 {
3265 "PostScript", "*.ps",
3266 "Acrobat pdf", "*.pdf",
3267 "SVG vector", "*.svg",
3268 "Gif files", "*.gif",
3269 "Png files", "*.png",
3270 "Gif files", "*.gif",
3271 "Jpeg files", "*.jpeg",
3272 "Xpm files", "*.xpm",
3273 "Bmp files", "*.bmp",
3274 "Xml files", "*.xml",
3275 "Tiff files", "*.tiff",
3276 "Csv files", "*.csv",
3277 "Macro files", "*.C",
3278 "ROOT files", "*.root",
3279 "All files", "*",
3280 NULL, NULL
3281 };
3282
3283 static TString dir(".");
3284
3285 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
3286
3287 fi.fFileTypes = (const char**)gSaveAsTypes;
3288 fi.fIniDir = StrDup(dir);
3289
3290 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
3291
3292 if (!fi.fFilename)
3293 return 0;
3294
3295 dir = fi.fIniDir;
3296
3297 const Int_t rc = SaveAs(num, fi.fFilename);
3298 if (rc>=0)
3299 return rc;
3300
3301 Warning("MStatusDisplay::SaveAs", "Unknown Extension: %s", fi.fFilename);
3302 return 0;
3303}
3304
3305// --------------------------------------------------------------------------
3306//
3307// Open contents of a MStatusDisplay with key name from file fname.
3308//
3309Int_t MStatusDisplay::Open(TString fname, const char *name)
3310{
3311 TFile file(fname, "READ");
3312 if (file.IsZombie())
3313 {
3314 gLog << warn << "WARNING - Cannot open file " << fname << endl;
3315 return 0;
3316 }
3317
3318 return Read(name);
3319}
3320
3321// --------------------------------------------------------------------------
3322//
3323// Opens an open dialog
3324//
3325Int_t MStatusDisplay::Open()
3326{
3327 static const char *gOpenTypes[] =
3328 {
3329 "ROOT files", "*.root",
3330 "All files", "*",
3331 NULL, NULL
3332 };
3333
3334 static TString dir(".");
3335
3336 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
3337
3338 fi.fFileTypes = (const char**)gOpenTypes;
3339 fi.fIniDir = StrDup(dir);
3340
3341 new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
3342
3343 if (!fi.fFilename)
3344 return 0;
3345
3346 dir = fi.fIniDir;
3347
3348 return Open(fi.fFilename);
3349}
3350
3351// --------------------------------------------------------------------------
3352//
3353// Change width of display. The height is calculated accordingly.
3354//
3355void MStatusDisplay::SetDisplayWidth(UInt_t dw)
3356{
3357 if (gROOT->IsBatch())
3358 {
3359 SetCanvasWidth(dw);
3360 return;
3361 }
3362
3363 // 4 == 2*default border with of canvas
3364 dw -= 4;
3365
3366 // Difference between canvas size and display size
3367 const UInt_t cw = GetWidth() -fTab->GetWidth();
3368 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3369
3370 const UInt_t dh = TMath::Nint((dw - cw)/1.5 + ch);
3371
3372 Resize(dw, dh); // Set display size
3373}
3374
3375// --------------------------------------------------------------------------
3376//
3377// Change height of display. The width is calculated accordingly.
3378//
3379void MStatusDisplay::SetDisplayHeight(UInt_t dh)
3380{
3381 if (gROOT->IsBatch())
3382 {
3383 SetCanvasHeight(dh);
3384 return;
3385 }
3386
3387 // 4 == 2*default border with of canvas
3388 dh -= 4;
3389
3390 // Difference between canvas size and display size
3391 const UInt_t cw = GetWidth() -fTab->GetWidth();
3392 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3393
3394 const UInt_t dw = TMath::Nint((dh - ch)*1.5 + cw);
3395
3396 Resize(dw, dh); // Set display size
3397}
3398
3399// --------------------------------------------------------------------------
3400//
3401// Change width of canvas. The height is calculated accordingly.
3402//
3403void MStatusDisplay::SetCanvasWidth(UInt_t w)
3404{
3405 // 4 == 2*default border with of canvas
3406 w += 4;
3407
3408 if (gROOT->IsBatch())
3409 {
3410 Resize(w, 3*w/2);
3411 return;
3412 }
3413
3414 // Difference between canvas size and display size
3415 const UInt_t cw = GetWidth() -fTab->GetWidth();
3416 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3417
3418 const UInt_t h = TMath::Nint(w/1.5 + ch);
3419
3420 Resize(w + cw, h); // Set display size
3421}
3422
3423// --------------------------------------------------------------------------
3424//
3425// Change height of canvas. The width is calculated accordingly.
3426//
3427void MStatusDisplay::SetCanvasHeight(UInt_t h)
3428{
3429 // 4 == 2*default border with of canvas
3430 h += 4;
3431
3432 if (gROOT->IsBatch())
3433 {
3434 Resize(2*h/3, h);
3435 return;
3436 }
3437
3438 // Difference between canvas size and display size
3439 const UInt_t cw = GetWidth() -fTab->GetWidth();
3440 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3441
3442 // 4 == 2*default border with of canvas
3443 const UInt_t dw = TMath::Nint((h+4)*1.5 + cw);
3444
3445 Resize(dw, h + ch); // Set display size
3446}
3447
3448// --------------------------------------------------------------------------
3449//
3450// Calculate width and height of the display such that it fits into the
3451// defined box.
3452//
3453void MStatusDisplay::SetDisplaySize(UInt_t w, UInt_t h)
3454{
3455 if (gROOT->IsBatch())
3456 return;
3457
3458 SetDisplayHeight(h);
3459
3460 if (GetWidth()>w)
3461 SetDisplayWidth(w);
3462}
3463
3464// --------------------------------------------------------------------------
3465//
3466// Calculate an optimum size for the display from the desktop size
3467//
3468void MStatusDisplay::SetOptimumSize()
3469{
3470 if (gROOT->IsBatch())
3471 return;
3472
3473 const UInt_t w = TMath::Nint(0.95*gClient->GetDisplayWidth());
3474 const UInt_t h = TMath::Nint(0.95*gClient->GetDisplayHeight());
3475
3476 SetDisplaySize(w, h);
3477}
3478
3479
3480Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
3481{
3482 //
3483 // The initialization of the GUI is not yet enough finished...
3484 //
3485 if (!fTab)
3486 return kTRUE;
3487
3488 UInt_t w = evt->fWidth;
3489 UInt_t h = evt->fHeight;
3490
3491 const Bool_t wchanged = w!=GetWidth()-fTab->GetWidth();
3492 const Bool_t hchanged = h!=GetHeight()-fTab->GetHeight();
3493
3494 if (!wchanged && !hchanged)
3495 {
3496 Layout();
3497 // FIXME: Make sure that this doesn't result in endless loops.
3498 return kTRUE;
3499 }
3500
3501 if (GetWidth()==1 && GetHeight()==1)
3502 return kTRUE;
3503
3504 // calculate the constant part of the window
3505 const UInt_t cw = GetWidth() -fTab->GetWidth();
3506 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3507
3508 // calculate new size of frame (canvas @ 2:3)
3509 if (hchanged)
3510 w = TMath::Nint((h-ch)*1.5+cw);
3511 else
3512 h = TMath::Nint((w-cw)/1.5+ch);
3513
3514 // resize frame
3515 Resize(w, h);
3516
3517 return kTRUE;
3518}
3519
3520Bool_t MStatusDisplay::HandleEvent(Event_t *event)
3521{
3522 // Instead of doing this in CloseWindow (called from HandleEvent)
3523 // we do it here. This makes sure, that handle event doesn't
3524 // execute code after deleting this.
3525 if (event->fType==kDestroyNotify)
3526 {
3527 if (Close())
3528 delete this;
3529// Close();
3530 return kTRUE;
3531 }
3532
3533 const Bool_t rc = TGMainFrame::HandleEvent(event);
3534
3535 //
3536 // This fixes a bug in older root versions which makes
3537 // TCanvas crash if gPad==NULL. So we make sure, that
3538 // gPad!=NULL -- be carfull, this may have other side
3539 // effects.
3540 //
3541#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
3542 if (!gPad && fTab)
3543 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
3544 {
3545 TCanvas *c = GetCanvas(i);
3546 if (c)
3547 {
3548 c->cd();
3549 gLog << dbg << "MStatusDisplay::HandleEvent - Workaround: gPad=" << gPad << "." << endl;
3550 break;
3551 }
3552 }
3553#endif
3554
3555 return rc;
3556}
Note: See TracBrowser for help on using the repository browser.