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

Last change on this file since 11487 was 11412, checked in by tbretz, 13 years ago
Fixed a problem with a possible infinite loop in the display.
File size: 99.5 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 //
1204 // If we are in a multithreaded environment (gThreadXAR) we
1205 // have to make sure, that thus function is called from
1206 // the main thread.
1207 //
1208 if (gThreadXAR)
1209 {
1210 // Tell the X-Requester how to call this method
1211 const TString str = MString::Format("%ld", (ULong_t)f);
1212
1213 TMethodCall call(IsA(), "UpdateTab", "NULL");
1214 void *arr[4] = { NULL, &call, this, (void*)(const char*)str };
1215
1216 // If this is not the main thread return
1217 if (((*gThreadXAR)("METH", 4, arr, NULL)))
1218 return;
1219 }
1220
1221 TCanvas *c=GetCanvas(*f);
1222 if (!c)
1223 return;
1224
1225 const TString name = c->GetName();
1226 const TString title = c->GetTitle();
1227
1228 if (!gROOT->IsBatch())
1229 fStatusBar->SetText(title, 0);
1230
1231 // It seems that we cannot use this because an update
1232 // initiated by a gui event can interfere with the regular
1233 // update from the timer and then ProcessEvents will
1234 // end in an infinite loop.
1235 // SetStatusLine1(title);
1236
1237
1238 //
1239 // Secure calls to update the tabs against itself, at least
1240 // c->Paint() or c->Flush() may crash X (bad drawable).
1241 // This makes sure, that a X call is not interuppted by
1242 // another X-call which was started from an gui interrrupt
1243 // in the same thread
1244 //
1245 const Int_t rc = fMutex->TryLock();
1246 if (rc==13)
1247 gLog << warn << "MStatusDisplay::UpdateTab - mutex is already locked by this thread." << endl;
1248
1249 if (rc)
1250 return;
1251
1252#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
1253 TPad *padsav = (TPad*)gPad;
1254 if (!gPad)
1255 c->cd();
1256#endif
1257
1258 if (!c->IsBatch())
1259 c->FeedbackMode(kFALSE); // Goto double buffer mode
1260
1261 //
1262 // Doing this ourself gives us the possibility to repaint
1263 // the canvas in any case (Paint() instead of PaintModified())
1264 //
1265 c->Paint(); // Repaint all pads
1266 c->Flush(); // Copy all pad pixmaps to the screen
1267
1268#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
1269 if (padsav)
1270 padsav->cd();
1271 else
1272 gPad=NULL;
1273#endif
1274
1275 //c->SetCursor(kCross);
1276
1277 // Old version
1278 //c->Modified();
1279 //c->Update();
1280 //c->Paint();
1281
1282 fMutex->UnLock();
1283}
1284
1285TString MStatusDisplay::PrintDialog(TString &p, TString &c, TString &t, const char *ext)
1286{
1287 // If not in batch mode open a user dialog
1288 if (!gROOT->IsBatch())
1289 {
1290 char *cprinter = StrDup(p);
1291 char *ccmd = StrDup(c);
1292
1293 Int_t rc=0;
1294 new TGPrintDialog(fClient->GetRoot(), this, 400, 150, &cprinter, &ccmd, &rc);
1295 if (rc)
1296 {
1297 p = cprinter; // default has been changed
1298 c = ccmd;
1299 }
1300
1301 delete [] cprinter;
1302 delete [] ccmd;
1303
1304 if (!rc)
1305 return "";
1306 }
1307
1308 if (c.Contains("%f") && ext)
1309 {
1310 // Get temporary file name
1311 TString name = "mars";
1312
1313 FILE *f = gSystem->TempFileName(name, t);
1314 if (!f)
1315 {
1316 *fLog << warn << "MStatusDisplay::PrintDialog: Couldn't create temporary file in " << t << endl;
1317 SetStatusLine2("failed!");
1318 return "";
1319 }
1320 fclose(f);
1321
1322 // remove temp file
1323 gSystem->Unlink(name);
1324 name += ".";
1325 name += ext;
1326
1327 t = name;
1328 }
1329
1330 // compile command
1331 TString cmd(c);
1332
1333 // if sprinter.IsNull we assume that everything around %p can
1334 // be omitted and the program uses some kind of default
1335 if (p.IsNull())
1336 {
1337 TString sub;
1338 while (1)
1339 {
1340 sub = TString(cmd(TRegexp(" .*%p.* "))).Strip(TString::kBoth);
1341 if (sub.IsNull())
1342 break;
1343
1344 cmd.ReplaceAll(sub, "");
1345 }
1346 }
1347
1348 cmd.ReplaceAll("%p", p);
1349 cmd.ReplaceAll("%f", t);
1350
1351 return cmd;
1352}
1353
1354// --------------------------------------------------------------------------
1355//
1356// Saves the given canvas (pad) or all pads (num<0) as a temporary
1357// postscript file and prints it.
1358//
1359// The default command line c is: lpr -P%p %f
1360// %p: printer name
1361// %f: temporary file name
1362//
1363// The default printer name p is: <empty>
1364//
1365// Both can be changed in .rootrc by:
1366// PrintPS.Printer
1367// PrintPS.Command
1368//
1369// Ant the location of the temporary file t can by changed by
1370// Print.Directory
1371// the default is the system default directory (normally /tmp)
1372//
1373Int_t MStatusDisplay::PrintPS(Int_t num, const char *p, const char *c, const char *t)
1374{
1375 static TString sprinter = gEnv->GetValue("PrintPS.Printer", p&&*p?p:"");
1376 static TString scmd = gEnv->GetValue("PrintPS.Command", c&&*c?c:"lpr -P%p %f");
1377
1378 TString tmp = gEnv->GetValue("Print.Directory", t&&*t?t:gSystem->TempDirectory());
1379
1380 TString cmd = PrintDialog(sprinter, scmd, tmp, "ps");
1381 if (cmd.IsNull())
1382 return 0;
1383
1384 // set status lines
1385 SetStatusLine1("Printing...");
1386 SetStatusLine2("");
1387
1388 // print to temporary file
1389 const Int_t pages = SaveAsPS(num, tmp);
1390
1391 // check
1392 if (!pages)
1393 {
1394 *fLog << warn << "MStatusDisplay::Print: Sorry, couldn't save file as temporary postscript!" << endl;
1395 SetStatusLine2("Failed!");
1396 return 0;
1397 }
1398
1399 // execute command
1400 *fLog << dbg << "Executing: " << cmd << endl;
1401 gSystem->Exec(cmd);
1402
1403 // remove temporary file
1404 gSystem->Unlink(tmp);
1405
1406 SetStatusLine2(MString::Format("Done (%dpage(s))", pages));
1407
1408 return pages;
1409}
1410
1411// --------------------------------------------------------------------------
1412//
1413// Remove tab no i if this tab contains a TRootEmbeddedCanvas
1414//
1415void MStatusDisplay::RemoveTab(int i)
1416{
1417 TGCompositeFrame *f = fTab->GetTabContainer(i);
1418 if (!f)
1419 return;
1420
1421 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(*f);
1422 if (!ec)
1423 return;
1424
1425 TCanvas *c = ec->GetCanvas();
1426 if (!c)
1427 return;
1428
1429 // Repair the "Workaround" being in the RecursiveRemove list
1430 // but not in a list checked by gROOT->FindObject
1431 //gROOT->GetListOfCleanups()->Remove(c);
1432 //gROOT->GetListOfCanvases()->Add(c);
1433
1434 // FIXME: Due to our workaround this is necessary for a successfull deletion
1435 //c->cd();
1436
1437 const TString name(c->GetName());
1438
1439 f->RemoveFrame(ec);
1440 delete fList->Remove(ec);
1441
1442 fTab->RemoveTab(i);
1443 fTab->SetTab(0);
1444
1445 TGComboBox *box = (TGComboBox*)fList->FindWidget(kTabs);
1446 box->RemoveEntry(i);
1447 for (int j=i; j<box->GetListBox()->GetNumberOfEntries(); j++)
1448 {
1449 TGTextLBEntry *entry = (TGTextLBEntry *)box->GetListBox()->Select(j+1, kFALSE);
1450 box->AddEntry(entry->GetText()->GetString(), j);
1451 box->RemoveEntry(j+1);
1452 }
1453 box->GetListBox()->Select(0);
1454
1455 // Looks strange...
1456 // const Int_t n = fTab->GetNumberOfTabs();
1457 // fTab->SetTab(i<=n-1 ? i : i-1);
1458
1459 // layout and map new tab
1460 Layout(); // seems to layout the TGCompositeFrame
1461 MapSubwindows(); // maps the TGCompositeFrame
1462 Layout(); // layout the embedded canvas in the frame
1463
1464 UpdateMemory();
1465
1466 // display new tab in the main frame
1467 // FIXME: This is a workaround, because TApplication::Run is not
1468 // thread safe against ProcessEvents. We assume, that if
1469 // we are not in the Main-Thread ProcessEvents() is
1470 // called by the TApplication Event Loop...
1471 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
1472 gClient->ProcessEventsFor(fTab);
1473
1474 *fLog << inf << "Removed Tab #" << i << " '" << name << "'" << endl;
1475}
1476
1477// --------------------------------------------------------------------------
1478//
1479// Use this to check whether the MStatusDisplay still contains the
1480// TCanvas c. It could be removed meanwhile by menu usage.
1481//
1482Bool_t MStatusDisplay::HasCanvas(const TCanvas *c) const
1483{
1484 if (!c)
1485 return kFALSE;
1486
1487 // If you encounter unexpected crashes here, check if
1488 // a canvas is existing twice in the list or has been
1489 // deleted by accident. (Check AddTab)
1490
1491 if (gROOT->IsBatch())
1492 return (Bool_t)fBatch->FindObject(c);
1493
1494 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
1495 if (c==GetCanvas(i))
1496 return kTRUE;
1497 return kFALSE;
1498}
1499
1500/*
1501 if (...)
1502 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1503 else
1504 fMenu->RemovePopup("CaOs");
1505 fMenu->Resize(fMenu->GetDefaultSize());
1506 MapSubwindows();
1507 MapWindow();
1508 */
1509
1510void MStatusDisplay::Reset()
1511{
1512 if (gROOT->IsBatch())
1513 {
1514 fBatch->Delete();
1515 return;
1516 }
1517
1518 for (int i=fTab->GetNumberOfTabs()-1; i>0; i--)
1519 RemoveTab(i);
1520}
1521
1522Bool_t MStatusDisplay::SaveLogAsPS(const char *n) const
1523{
1524 TString name(n);
1525 AddExtension(name, "ps");
1526
1527 // Code taken from TGTextEdit::Print
1528 const TString pipe = MString::Format("a2ps -o%s", name.Data());
1529 FILE *p = gSystem->OpenPipe(pipe, "w");
1530 if (!p)
1531 {
1532 *fLog << err << "ERROR - Couldn't open pipe " << pipe << ": " << strerror(errno) << endl;
1533 return kFALSE;
1534 }
1535
1536 TGText *text = fLogBox->GetText();
1537
1538 char *buf1, *buf2;
1539 Long_t len;
1540 ULong_t i = 0;
1541 TGLongPosition pos;
1542
1543 Bool_t rc = kTRUE;
1544
1545 pos.fX = pos.fY = 0;
1546 while (pos.fY < text->RowCount())
1547 {
1548 len = text->GetLineLength(pos.fY);
1549 buf1 = text->GetLine(pos, len);
1550 buf2 = new char[len + 2];
1551 strncpy(buf2, buf1, (UInt_t)len);
1552 buf2[len] = '\n';
1553 buf2[len+1] = '\0';
1554 while (buf2[i] != '\0') {
1555 if (buf2[i] == '\t') {
1556 ULong_t j = i+1;
1557 while (buf2[j] == 16 && buf2[j] != '\0')
1558 j++;
1559 strcpy(buf2+i+1, buf2+j);
1560 }
1561 i++;
1562 }
1563
1564 len = sizeof(char)*(strlen(buf2)+1);
1565
1566 const size_t ret = fwrite(buf2, len, 1, p);
1567 delete [] buf1;
1568 delete [] buf2;
1569
1570 if (ret!=1)
1571 {
1572 *fLog << err << "ERROR - fwrite to pipe " << pipe << " failed: " << strerror(errno) << endl;
1573 rc = kFALSE;
1574 break;
1575 }
1576
1577 pos.fY++;
1578 }
1579 gSystem->ClosePipe(p);
1580 return kTRUE;
1581}
1582
1583// --------------------------------------------------------------------------
1584//
1585// Print the log text.
1586//
1587// The default command line c is: a2ps -P%p
1588// %p: printer name
1589//
1590// The default printer name p is: <empty>
1591//
1592// Both can be changed in .rootrc by:
1593// PrintText.Printer
1594// PrintText.Command
1595//
1596Bool_t MStatusDisplay::PrintLog(const char *p, const char *c)
1597{
1598 static TString sprinter = gEnv->GetValue("PrintText.Printer", p&&*p?p:"");
1599 static TString scmd = gEnv->GetValue("PrintText.Command", c&&*c?c:"a2ps -P%p");
1600
1601 TString tmp;
1602 TString cmd = PrintDialog(sprinter, scmd, tmp);
1603 if (cmd.IsNull())
1604 return kFALSE;
1605
1606 // set status lines
1607 SetStatusLine1("Printing...");
1608 SetStatusLine2("");
1609
1610 // print to temporary file
1611 if (!SaveLogAsPS(cmd))
1612 {
1613 *fLog << warn << "MStatusDisplay::PrintLog: Sorry, couldn't create postscript!" << endl;
1614 SetStatusLine2("Failed!");
1615 return kFALSE;
1616 }
1617
1618 // execute command
1619 *fLog << dbg << "Executing: " << cmd << endl;
1620 gSystem->Exec(cmd);
1621
1622 SetStatusLine2("Done.");
1623
1624 return kTRUE;
1625}
1626
1627// --------------------------------------------------------------------------
1628//
1629// Process the kC_COMMAND, kCM_MENU messages
1630//
1631Bool_t MStatusDisplay::ProcessMessageCommandMenu(Long_t id)
1632{
1633 switch (id)
1634 {
1635 case kLoopPause:
1636 {
1637 TGPopupMenu *m = GetPopup("Loop");
1638 if (!m)
1639 return kTRUE;
1640
1641 if (fStatus==kLoopNone)
1642 {
1643 fStatus = (Status_t)kLoopPause;
1644 m->CheckEntry(kLoopPause);
1645 m->EnableEntry(kLoopStep);
1646 return kTRUE;
1647 }
1648 if (fStatus==kLoopPause)
1649 {
1650 fStatus = (Status_t)kLoopNone;
1651 m->UnCheckEntry(kLoopPause);
1652 m->DisableEntry(kLoopStep);
1653 return kTRUE;
1654 }
1655 }
1656 return kTRUE;
1657
1658 case kLoopStep:
1659 fStatus = (Status_t)kLoopStep;
1660 return kTRUE;
1661
1662 case kLoopStop:
1663 case kFileClose:
1664 case kFileExit:
1665 if (id==kFileExit || id==kFileClose)
1666 if (Close())
1667 delete this;
1668 fStatus = (Status_t)id;
1669 return kTRUE;
1670
1671 case kFileCanvas:
1672 new TCanvas;
1673 return kTRUE;
1674
1675 case kFileBrowser:
1676 new TBrowser;
1677 return kTRUE;
1678
1679 case kFileTab:
1680 AddTab(MString::Format("%d", fTab->GetNumberOfTabs()));
1681 return kTRUE;
1682
1683 case kFileReset:
1684 Reset();
1685 return kTRUE;
1686
1687 case kFileOpen:
1688 Open();
1689 return kTRUE;
1690
1691 case kFileSaveAs:
1692 SaveAs();
1693 return kTRUE;
1694
1695 case kFileSaveAsPS:
1696 SaveAsPS();
1697 return kTRUE;
1698
1699 case kFileSaveAsPDF:
1700 SaveAsPDF();
1701 return kTRUE;
1702
1703 case kFileSaveAsSVG:
1704 SaveAsSVG();
1705 return kTRUE;
1706
1707 case kFileSaveAsPNG:
1708 SaveAsPNG();
1709 return kTRUE;
1710
1711 case kFileSaveAsGIF:
1712 SaveAsGIF();
1713 return kTRUE;
1714
1715 case kFileSaveAsXPM:
1716 SaveAsXPM();
1717 return kTRUE;
1718
1719 case kFileSaveAsJPG:
1720 SaveAsJPG();
1721 return kTRUE;
1722
1723 case kFileSaveAsTIFF:
1724 SaveAsTIFF();
1725 return kTRUE;
1726
1727 case kFileSaveAsBMP:
1728 SaveAsBMP();
1729 return kTRUE;
1730
1731 case kFileSaveAsXML:
1732 SaveAsXML();
1733 return kTRUE;
1734
1735 case kFileSaveAsCSV:
1736 SaveAsCSV();
1737 return kTRUE;
1738
1739 case kFileSaveAsC:
1740 SaveAsC();
1741 return kTRUE;
1742
1743 case kFileSaveAsRoot:
1744 SaveAsRoot();
1745 return kTRUE;
1746
1747 case kFileSaveAsPlainRoot:
1748 SaveAsPlainRoot(kTRUE);
1749 return kTRUE;
1750
1751 case kFilePrint:
1752 PrintPS();
1753 return kTRUE;
1754
1755 case kTabSaveAs:
1756 SaveAs(fTab->GetCurrent());
1757 return kTRUE;
1758
1759 case kTabSaveAsPS:
1760 SaveAsPS(fTab->GetCurrent());
1761 return kTRUE;
1762
1763 case kTabSaveAsPDF:
1764 SaveAsPDF(fTab->GetCurrent());
1765 return kTRUE;
1766
1767 case kTabSaveAsSVG:
1768 SaveAsSVG(fTab->GetCurrent());
1769 return kTRUE;
1770
1771 case kTabSaveAsPNG:
1772 SaveAsPNG(fTab->GetCurrent());
1773 return kTRUE;
1774
1775 case kTabSaveAsGIF:
1776 SaveAsGIF(fTab->GetCurrent());
1777 return kTRUE;
1778
1779 case kTabSaveAsXPM:
1780 SaveAsXPM(fTab->GetCurrent());
1781 return kTRUE;
1782
1783 case kTabSaveAsJPG:
1784 SaveAsJPG(fTab->GetCurrent());
1785 return kTRUE;
1786
1787 case kTabSaveAsTIFF:
1788 SaveAsTIFF(fTab->GetCurrent());
1789 return kTRUE;
1790
1791 case kTabSaveAsBMP:
1792 SaveAsBMP(fTab->GetCurrent());
1793 return kTRUE;
1794
1795 case kTabSaveAsXML:
1796 SaveAsXML(fTab->GetCurrent());
1797 return kTRUE;
1798
1799 case kTabSaveAsCSV:
1800 SaveAsCSV(fTab->GetCurrent());
1801 return kTRUE;
1802
1803 case kTabSaveAsC:
1804 SaveAsC(fTab->GetCurrent());
1805 return kTRUE;
1806
1807 case kTabSaveAsPlainRoot:
1808 SaveAsPlainRoot(fTab->GetCurrent());
1809 return kTRUE;
1810
1811 case kTabSaveAsRoot:
1812 SaveAsRoot(fTab->GetCurrent());
1813 return kTRUE;
1814
1815 case kTabPrint:
1816 PrintPS(fTab->GetCurrent());
1817 return kTRUE;
1818
1819 case kTabNext:
1820 fTab->SetTab(fTab->GetCurrent()+1);
1821 return kTRUE;
1822
1823 case kTabPrevious:
1824 fTab->SetTab(fTab->GetCurrent()-1);
1825 return kTRUE;
1826
1827 case kTabRemove:
1828 RemoveTab(fTab->GetCurrent());
1829 return kTRUE;
1830
1831 case kSize640:
1832 SetDisplaySize(640, 480);
1833 return kTRUE;
1834 case kSize768:
1835 SetDisplaySize(768, 576);
1836 return kTRUE;
1837 case kSize800:
1838 SetDisplaySize(800, 600);
1839 return kTRUE;
1840 case kSize960:
1841 SetDisplaySize(960, 720);
1842 return kTRUE;
1843 case kSize1024:
1844 SetDisplaySize(1024, 768);
1845 return kTRUE;
1846 case kSize1152:
1847 SetDisplaySize(1152, 864);
1848 return kTRUE;
1849 case kSize1280:
1850 SetDisplaySize(1280, 1024);
1851 return kTRUE;
1852 case kSize1400:
1853 SetDisplaySize(1400, 1050);
1854 return kTRUE;
1855 case kSize1600:
1856 SetDisplaySize(1600, 1200);
1857 return kTRUE;
1858 case kSizeOptimum:
1859 SetOptimumSize();
1860 return kTRUE;
1861
1862 case kLogClear:
1863 fLogBox->Clear();
1864 return kTRUE;
1865 case kLogCopy:
1866 fLogBox->Copy();
1867 return kTRUE;
1868 case kLogSelect:
1869 fLogBox->SelectAll();
1870 return kTRUE;
1871 case kLogFind:
1872 new MSearch(this);
1873 return kTRUE;
1874 case kLogSave:
1875 SetStatusLine1("Saving log...");
1876 SetStatusLine2("");
1877 *fLog << inf << "Saving log... " << flush;
1878 if (fLogBox->GetText()->Save(MString::Format("%s.log", gROOT->GetName())))
1879 {
1880 *fLog << "done." << endl;
1881 SetStatusLine2("done.");
1882 }
1883 else
1884 {
1885 *fLog << "failed!" << endl;
1886 SetStatusLine2("Failed!");
1887 }
1888 return kTRUE;
1889
1890 case kLogAppend:
1891 SetStatusLine1("Appending log...");
1892 SetStatusLine2("");
1893 *fLog << inf << "Appending log... " << flush;
1894 if (fLogBox->GetText()->Append(MString::Format("%s.log", gROOT->GetName())))
1895 {
1896 *fLog << "done." << endl;
1897 SetStatusLine2("done.");
1898 }
1899 else
1900 {
1901 *fLog << "failed!" << endl;
1902 SetStatusLine2("Failed!");
1903 }
1904 return kTRUE;
1905
1906 case kLogPrint:
1907 PrintLog();
1908 return kTRUE;
1909#ifdef DEBUG
1910 default:
1911 cout << "Command-Menu #" << id << endl;
1912#endif
1913 }
1914 return kTRUE;
1915
1916}
1917
1918// --------------------------------------------------------------------------
1919//
1920// Process the kC_COMMAND messages
1921//
1922Bool_t MStatusDisplay::ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2)
1923{
1924 switch (submsg)
1925 {
1926 case kCM_MENU: // 1
1927 return ProcessMessageCommandMenu(mp1); // mp2=userdata
1928 case kCM_TAB: // 8
1929 /*
1930 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
1931 fTab->GetTabContainer(i)->UnmapWindow();
1932 */
1933 UpdateTab(fTab->GetTabContainer(mp1));
1934 //fTab->GetTabContainer(mp1)->MapWindow();
1935
1936 /*
1937 if (mp1>0)
1938 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1939 else
1940 fMenu->RemovePopup("CaOs");
1941 fMenu->Resize(fMenu->GetDefaultSize());
1942 MapSubwindows();
1943 MapWindow();
1944 */
1945 return kTRUE;
1946 case kCM_COMBOBOX: // 7
1947 if (mp1==kTabs)
1948 fTab->SetTab(mp2);
1949 return kTRUE;
1950#ifdef DEBUG
1951 case kCM_MENUSELECT: // 2
1952 cout << "Command-Menuselect #" << mp1 << " (UserData=" << (void*)mp2 << ")" << endl;
1953 return kTRUE;
1954
1955 case kCM_BUTTON: // 3
1956 cout << "Command-Button." << endl;
1957 return kTRUE;
1958
1959 case kCM_CHECKBUTTON: // 4
1960 cout << "Command-CheckButton." << endl;
1961 return kTRUE;
1962
1963 case kCM_RADIOBUTTON: // 5
1964 cout << "Command-RadioButton." << endl;
1965 return kTRUE;
1966
1967 case kCM_LISTBOX: // 6
1968 cout << "Command-Listbox #" << mp1 << " (LineId #" << mp2 << ")" << endl;
1969 return kTRUE;
1970 default:
1971 cout << "Command: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1972#endif
1973 }
1974 return kTRUE;
1975}
1976
1977// --------------------------------------------------------------------------
1978//
1979// Process the kC_TEXTVIEW messages
1980//
1981Bool_t MStatusDisplay::ProcessMessageTextview(Long_t /*submsg*/, Long_t /*mp1*/, Long_t /*mp2*/)
1982{
1983 // kC_TEXTVIEW, kTXT_ISMARKED, widget id, [true|false] //
1984 // kC_TEXTVIEW, kTXT_DATACHANGE, widget id, 0 //
1985 // kC_TEXTVIEW, kTXT_CLICK2, widget id, position (y << 16) | x) //
1986 // kC_TEXTVIEW, kTXT_CLICK3, widget id, position (y << 16) | x) //
1987 // kC_TEXTVIEW, kTXT_F3, widget id, true //
1988 // kC_TEXTVIEW, kTXT_OPEN, widget id, 0 //
1989 // kC_TEXTVIEW, kTXT_CLOSE, widget id, 0 //
1990 // kC_TEXTVIEW, kTXT_SAVE, widget id, 0 //
1991#ifdef DEBUG
1992 switch (submsg)
1993 {
1994 case kTXT_ISMARKED:
1995 cout << "Textview-IsMarked #" << mp1 << " " << (mp2?"yes":"no") << endl;
1996 return kTRUE;
1997
1998 case kTXT_DATACHANGE:
1999 cout << "Textview-DataChange #" << mp1 << endl;
2000 return kTRUE;
2001
2002 case kTXT_CLICK2:
2003 cout << "Textview-Click2 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
2004 return kTRUE;
2005
2006 case kTXT_CLICK3:
2007 cout << "Textview-Click3 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
2008 return kTRUE;
2009
2010 case kTXT_F3:
2011 cout << "Textview-F3 #" << mp1 << endl;
2012 return kTRUE;
2013
2014 case kTXT_OPEN:
2015 cout << "Textview-Open #" << mp1 << endl;
2016 return kTRUE;
2017
2018 case kTXT_CLOSE:
2019 cout << "Textview-Close #" << mp1 << endl;
2020 return kTRUE;
2021
2022 case kTXT_SAVE:
2023 cout << "Textview-Save #" << mp1 << endl;
2024 return kTRUE;
2025
2026 default:
2027 cout << "Textview: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2028 }
2029#endif
2030 return kTRUE;
2031}
2032
2033// --------------------------------------------------------------------------
2034//
2035// Process the kC_USER messages
2036//
2037Bool_t MStatusDisplay::ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2)
2038{
2039 // kS_START, case sensitive | backward<<1, char *txt
2040 switch (submsg)
2041 {
2042 case kS_START:
2043 fLogBox->Search((char*)mp2, !(mp1&2>>1), mp1&1);
2044 return kTRUE;
2045#ifdef DEBUG
2046 default:
2047 cout << "User: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2048#endif
2049 }
2050 return kTRUE;
2051}
2052
2053// --------------------------------------------------------------------------
2054//
2055// Process the messages from the GUI
2056//
2057Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
2058{
2059 // Can be found in WidgetMessageTypes.h
2060#ifdef DEBUG
2061 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
2062 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2063#endif
2064 switch (GET_MSG(msg))
2065 {
2066 case kC_COMMAND: // 1
2067 return ProcessMessageCommand(GET_SUBMSG(msg), mp1, mp2);
2068
2069 case kC_TEXTVIEW: // 9
2070 return ProcessMessageTextview(GET_SUBMSG(msg), mp1, mp2);
2071
2072 case kC_USER: // 1001
2073 return ProcessMessageUser(GET_SUBMSG(msg), mp1, mp2);
2074 }
2075#ifdef DEBUG
2076 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
2077 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
2078#endif
2079 return kTRUE;
2080}
2081
2082Bool_t MStatusDisplay::Close()
2083{
2084 // Got close message for this MainFrame. Calls parent CloseWindow()
2085 // (which destroys the window) and terminate the application.
2086 // The close message is generated by the window manager when its close
2087 // window menu item is selected.
2088
2089 // CloseWindow must be overwritten because otherwise CloseWindow
2090 // and the destructor are calling DestroyWindow which seems to be
2091 // in conflict with the TRootEmbeddedCanvas.
2092
2093 // FIXME: Make sure that the Status Display is deleted from every
2094 // where (eg Eventloop) first!
2095
2096 //gLog << dbg << fName << " is on heap: " << (int)IsOnHeap() << endl;
2097
2098 if (TestBit(kExitLoopOnExit) || TestBit(kExitLoopOnClose))
2099 {
2100 //gLog << dbg << "CloseWindow() calling ExitLoop." << endl;
2101 gSystem->ExitLoop();
2102 }
2103
2104 if (fIsLocked<=0 && IsOnHeap())
2105 return kTRUE;
2106
2107 fStatus = kFileExit;
2108 return kFALSE;
2109}
2110
2111void MStatusDisplay::CloseWindow()
2112{
2113 if (Close())
2114 delete this;
2115}
2116
2117// --------------------------------------------------------------------------
2118//
2119// Calls SetBit(kNoContextMenu) for all TCanvas objects found in the
2120// Tabs.
2121//
2122void MStatusDisplay::SetNoContextMenu(Bool_t flag)
2123{
2124 if (fIsLocked>1 || gROOT->IsBatch())
2125 return;
2126
2127 flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
2128
2129 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
2130 {
2131 TCanvas *c = GetCanvas(i);
2132 if (c)
2133 flag ? c->SetBit(kNoContextMenu) : c->ResetBit(kNoContextMenu);
2134 }
2135}
2136
2137// --------------------------------------------------------------------------
2138//
2139// Update the memory display in the status bar
2140//
2141void MStatusDisplay::UpdateMemory() const
2142{
2143 const TString path = MString::Format("/proc/%d/status", gSystem->GetPid());
2144 if (gSystem->AccessPathName(path, kFileExists))
2145 return;
2146
2147 TEnv env(path);
2148 const UInt_t kb = env.GetValue("VmSize", 0);
2149 if (kb==0)
2150 return;
2151
2152 char type = 'k';
2153 Float_t val = kb;
2154
2155 if (val>999)
2156 {
2157 type = 'M';
2158 val /= 1000;
2159 }
2160 if (val>999)
2161 {
2162 type = 'G';
2163 val /= 1000;
2164 }
2165 const TString txt = MString::Format("%.1f%c", val, type);
2166 fStatusBar->SetText(txt, 2);
2167}
2168
2169// --------------------------------------------------------------------------
2170//
2171// Updates the canvas (if existing) in the currenly displayed Tab.
2172// The update intervall is controlled by StartUpdate and StopUpdate
2173//
2174Bool_t MStatusDisplay::HandleTimer(TTimer *timer)
2175{
2176 if (gROOT->IsBatch())
2177 return kTRUE;
2178
2179 UpdateMemory();
2180
2181 const Int_t c = fTab->GetCurrent();
2182
2183 // Skip Legend Tab
2184 if (c==0)
2185 return kTRUE;
2186
2187 // Update a canvas tab (if visible)
2188 if (timer==&fTimer && c!=fLogIdx)
2189 {
2190 UpdateTab(fTab->GetCurrentContainer());
2191 return kTRUE;
2192 }
2193
2194 // update the logbook tab (if visible)
2195 if (timer==&fLogTimer && c==fLogIdx)
2196 {
2197 fLog->UpdateGui();
2198
2199 /*
2200 if (!fLogBox->TestBit(kHasChanged))
2201 return kTRUE;
2202
2203 fLogBox->ResetBit(kHasChanged);
2204 */
2205 return kTRUE;
2206 }
2207
2208 return kTRUE;
2209}
2210
2211// --------------------------------------------------------------------------
2212//
2213// Find an object in a canvas (uses MStatusArray as helper)
2214//
2215void MStatusDisplay::PrintContent(Option_t *o) const
2216{
2217 MStatusArray(*this).Print(o);
2218}
2219
2220// --------------------------------------------------------------------------
2221//
2222// Find an object in a canvas (uses MStatusArray as helper)
2223//
2224TObject *MStatusDisplay::FindObjectInCanvas(const char *obj, const char *base, const char *canv) const
2225{
2226 return MStatusArray(*this).FindObjectInCanvas(obj, base, canv);
2227}
2228
2229// --------------------------------------------------------------------------
2230//
2231// Draws a clone of a canvas into a new canvas. Taken from TCanvas.
2232//
2233void MStatusDisplay::DrawClonePad(TCanvas &newc, TCanvas &oldc) const
2234{
2235 //copy pad attributes
2236 newc.Range(oldc.GetX1(),oldc.GetY1(),oldc.GetX2(),oldc.GetY2());
2237 newc.SetTickx(oldc.GetTickx());
2238 newc.SetTicky(oldc.GetTicky());
2239 newc.SetGridx(oldc.GetGridx());
2240 newc.SetGridy(oldc.GetGridy());
2241 newc.SetLogx(oldc.GetLogx());
2242 newc.SetLogy(oldc.GetLogy());
2243 newc.SetLogz(oldc.GetLogz());
2244 newc.SetBorderSize(oldc.GetBorderSize());
2245 newc.SetBorderMode(oldc.GetBorderMode());
2246 ((TAttLine&)oldc).Copy((TAttLine&)newc);
2247 ((TAttFill&)oldc).Copy((TAttFill&)newc);
2248 ((TAttPad&)oldc).Copy((TAttPad&)newc);
2249
2250 // This must be there: Otherwise GetDrawOption() won't work
2251 TVirtualPad *padsav = gPad;
2252 oldc.cd();
2253
2254 const Bool_t store = TH1::AddDirectoryStatus();
2255 TH1::AddDirectory(kFALSE);
2256
2257 //copy primitives
2258 TObject *obj;
2259 TIter next(oldc.GetListOfPrimitives());
2260 while ((obj=next()))
2261 {
2262 // Old line - I think it is not necessary anymore because of the cd()
2263 //gROOT->SetSelectedPad(&newc);
2264
2265 // Now make a clone of the object
2266 TObject *clone = obj->Clone();
2267
2268 // Clone also important bits (FIXME: Is this correct)
2269 clone->SetBit(obj->TestBits(kCannotPick|kNoContextMenu));
2270
2271 // Now make sure that the clones are deleted at a later time
2272 clone->SetBit(kCanDelete|kMustCleanup);
2273
2274 // FIXME: This is a workaround for the problem with the MAstroCatalog in
2275 // MHFalseSource. It doesn't harm. We'll still try to find the reason
2276 //if (clone->IsA()==TPad::Class())
2277 // gROOT->GetListOfCleanups()->Add(clone);
2278
2279 // Add the clone and its draw-option to the current pad
2280 TVirtualPad *save2 = gPad;
2281 gPad = &oldc; // Don't do this before Clone()!
2282 newc.GetListOfPrimitives()->Add(clone, obj->GetDrawOption());
2283 gPad = save2;
2284 }
2285 newc.Modified();
2286 newc.Update();
2287
2288 TH1::AddDirectory(store);
2289
2290 padsav->cd();
2291}
2292
2293// --------------------------------------------------------------------------
2294//
2295// Display the contexts of a TObjArray in the display (all canvases)
2296//
2297Bool_t MStatusDisplay::Display(const TObjArray &list, const char *tab)
2298{
2299 TIter Next(&list);
2300
2301 TObject *o=Next();
2302 if (!o)
2303 {
2304 *fLog << err << "MStatusDisplay::Display: No entry in TObjArray." << endl;
2305 return kFALSE;
2306 }
2307
2308 // The first entry in the list is a TNamed which is expected to
2309 // contain the status display title.
2310 fTitle = o->GetTitle();
2311
2312 TCanvas *c;
2313 while ((c=(TCanvas*)Next()))
2314 //if (!GetCanvas(c->GetName()))
2315 if (c->InheritsFrom(TCanvas::Class()))
2316 if (!tab || c->GetName()==(TString)tab)
2317 DrawClonePad(AddTab(c->GetName(), c->GetTitle()), *c);
2318
2319 return kTRUE;
2320}
2321
2322// --------------------------------------------------------------------------
2323//
2324// Reads the contents of a saved MStatusDisplay from a file.
2325//
2326Int_t MStatusDisplay::Read(const char *name, const char *tab)
2327{
2328 if (!gFile)
2329 {
2330 *fLog << warn << "MStatusDisplay::Read: No file found. Please create a TFile first." << endl;
2331 return 0;
2332 }
2333
2334 if (!gFile->IsOpen())
2335 {
2336 *fLog << warn << "MStatusDisplay::Read: File not open. Please open the TFile first." << endl;
2337 return 0;
2338 }
2339
2340 MStatusArray list;
2341
2342 Int_t n = list.Read(name);
2343
2344 //
2345 // If no status display was found with this name try to find canvases
2346 // in the file and display them instead.
2347 //
2348 if (n==0)
2349 {
2350 // Either read the title from the file or create our own
2351 TNamed *title=0;
2352 gFile->GetObject("Title", title); // FIXME: Is the list allowed to take ownership?
2353 list.Add(title ? title : new TNamed(GetName(), GetTitle()));
2354
2355 const Bool_t store = TH1::AddDirectoryStatus();
2356 TH1::AddDirectory(kFALSE);
2357
2358 TIter Next(gFile->GetListOfKeys());
2359 TObject *key = 0;
2360 while ((key=Next()))
2361 {
2362 MStatusArray *arr=0;
2363 gFile->GetObject(key->GetName(), arr);
2364 if (arr)
2365 {
2366 Display(*arr, tab);
2367 n++;
2368 continue;
2369 }
2370
2371 if (tab && key->GetName()!=(TString)tab)
2372 continue;
2373
2374 TCanvas *c=0;
2375 gFile->GetObject(key->GetName(), c);
2376
2377 // If key doesn't correspond to a TCanvas create a new canvas
2378 // and draw the object itself instead.
2379 if (!c)
2380 {
2381 TObject *obj = gFile->Get(key->GetName());
2382
2383 if (MParContainer::Overwrites(TObject::Class(), *obj, "Draw") ||
2384 MParContainer::Overwrites(TObject::Class(), *obj, "Paint"))
2385 {
2386 AddTab(key->GetName(), key->GetTitle());
2387 obj->SetBit(kCanDelete);
2388 obj->Draw();
2389 }
2390 // FIXME: Is the object deleted?
2391 continue;
2392 }
2393
2394 // Add the canvas to the list
2395 const TString name = c->GetName();
2396 const TString title = c->GetTitle();
2397 if (title.IsNull() || name==title)
2398 c->SetTitle(gFile->GetName());
2399 list.Add(c);
2400 }
2401
2402 TH1::AddDirectory(store);
2403
2404 if (list.GetEntries()<=1)
2405 {
2406 *fLog << warn << "MStatusDisplay::Read: No drawable objects read from " << gFile->GetName() << endl;
2407 return 0;
2408 }
2409
2410 *fLog << inf << "MStatusDisplay: " << list.GetEntries()-1 << " canvases directly read from file." << endl;
2411 }
2412
2413
2414 if (!Display(list, tab))
2415 {
2416 *fLog << err << "MStatusDisplay::Display: No entries found." << endl;
2417 return 0;
2418 }
2419
2420 if (n==0)
2421 return list.GetEntries();
2422
2423 *fLog << inf << "MStatusDisplay: Key " << name << " with " << n << " keys read from file." << endl;
2424 return n;
2425}
2426
2427// --------------------------------------------------------------------------
2428//
2429// Add all canvases to the MStatusArray
2430//
2431void MStatusDisplay::FillArray(MStatusArray &list, Int_t num) const
2432{
2433 Int_t from, to;
2434 GetCanvasRange(from, to, num);
2435
2436 TCanvas *c;
2437 for (int i=from; i<to; i++)
2438 if ((c = GetCanvas(i)))
2439 list.Add(c);
2440}
2441
2442// --------------------------------------------------------------------------
2443//
2444// Writes the contents of a MStatusDisplay to a file.
2445//
2446Int_t MStatusDisplay::Write(Int_t num, const char *name, Option_t *opt) const
2447{
2448 if (!gFile)
2449 {
2450 *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
2451 return 0;
2452 }
2453
2454 if (!gFile->IsOpen())
2455 {
2456 *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
2457 return 0;
2458 }
2459
2460 if (!gFile->IsWritable())
2461 {
2462 *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
2463 return 0;
2464 }
2465
2466 if (num==0)
2467 {
2468 *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
2469 return 0;
2470 }
2471
2472 if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
2473 {
2474 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
2475 return 0;
2476 }
2477 if (gROOT->IsBatch() && num>fBatch->GetSize())
2478 {
2479 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
2480 return 0;
2481 }
2482
2483 Int_t n = 0; // Number of keys written
2484
2485 TNamed named("Title", fTitle.Data());
2486
2487 if (TString(opt)=="plain")
2488 {
2489 // Get canvas range to store
2490 Int_t from, to;
2491 GetCanvasRange(from, to, num);
2492
2493 n += named.Write();
2494
2495 TCanvas *c;
2496 for (int i=from; i<to; i++)
2497 if ((c = GetCanvas(i)))
2498 n += c->Write();
2499 }
2500 else
2501 {
2502 // Be careful: So far Display() assumes that the TNamed
2503 // is the first entry in the list
2504 MStatusArray list;
2505 list.Add(&named);
2506
2507 FillArray(list, num);
2508
2509 n += list.Write(name, kSingleKey);
2510 }
2511
2512 *fLog << inf << "MStatusDisplay: " << n << " keys written to file as key " << name << "." << endl;
2513
2514 return n;
2515}
2516
2517// --------------------------------------------------------------------------
2518//
2519// Use this to start the synchronous (GUI eventloop driven) tab update.
2520// Can also be used to change the update intervall. If millisec<0
2521// the intervall given in SetUpdateTime is used. If the intervall in
2522// SetUpdateTime is <0 nothing is done. (Call SetUpdateTime(-1) to
2523// disable the automatic update in a MEventloop.
2524//
2525void MStatusDisplay::StartUpdate(Int_t millisec)
2526{
2527 if (fIsLocked>1)
2528 return;
2529
2530 if (fTimer.GetTime()<TTime(0))
2531 return;
2532 fTimer.Start(millisec);
2533}
2534
2535// --------------------------------------------------------------------------
2536//
2537// Stops the automatic GUI update
2538//
2539void MStatusDisplay::StopUpdate()
2540{
2541 if (fIsLocked>1)
2542 return;
2543
2544 fTimer.Stop();
2545}
2546
2547// --------------------------------------------------------------------------
2548//
2549// Set the update interval for the GUI update, see StartUpdate.
2550//
2551void MStatusDisplay::SetUpdateTime(Long_t t)
2552{
2553 fTimer.SetTime(t);
2554}
2555
2556// --------------------------------------------------------------------------
2557//
2558// If the filename name doesn't end with ext, ext is added to the end.
2559// If name.IsNull() "status" is assumed and the a number (>0) is added
2560// as "status-6".
2561// The extension is returned.
2562//
2563const TString &MStatusDisplay::AddExtension(TString &name, const TString &ext, Int_t num) const
2564{
2565 if (name.IsNull())
2566 {
2567 name = gROOT->GetName();
2568 if (num>0)
2569 {
2570 name += "-";
2571 name += num;
2572 }
2573 }
2574
2575 if (name.EndsWith("."+ext))
2576 return ext;
2577
2578 name += ".";
2579 name += ext;
2580
2581 return ext;
2582}
2583
2584Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
2585{
2586 if (gROOT->IsBatch())
2587 return (num>0 && num<=fBatch->GetSize()) || num<0;
2588
2589 if (num>=fTab->GetNumberOfTabs())
2590 {
2591 *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
2592 return kFALSE;
2593 }
2594 if (num==0)
2595 {
2596 *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
2597 return kFALSE;
2598 }
2599 if (fTab->GetNumberOfTabs()<2 || !gPad)
2600 {
2601 *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
2602 return kFALSE;
2603 }
2604 return kTRUE;
2605}
2606
2607// --------------------------------------------------------------------------
2608//
2609// Insert the following two lines into the postscript header:
2610//
2611// %%DocumentPaperSizes: a4
2612// %%Orientation: Landscape
2613//
2614void MStatusDisplay::UpdatePSHeader(const TString &name) const
2615{
2616 const TString newstr("%%DocumentPaperSizes: a4\n%%Orientation: Landscape\n");
2617
2618 TString tmp(name+"XXXXXX");
2619
2620 // FIXME: Use mkstemp instead
2621 if (!mktemp(const_cast<char*>(tmp.Data())))
2622 {
2623 *fLog << err << "ERROR - MStatusDisplay::UpdatePSHeader: mktemp failed." << endl;
2624 return;
2625 }
2626
2627 ifstream fin(name);
2628 ofstream fout(tmp);
2629 if (!fout)
2630 {
2631 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
2632 return;
2633 }
2634
2635 char c;
2636
2637 TString str;
2638 fin >> str >> c; // Read "%!PS-Adobe-2.0\n"
2639 fout << str << endl << newstr;
2640
2641 // Doing it in blocks seems not to gain much for small (MB) files
2642 while (fin)
2643 {
2644 fin.read(&c, 1);
2645 fout.write(&c, 1);
2646 }
2647
2648 gSystem->Unlink(name);
2649 gSystem->Rename(tmp, name);
2650}
2651
2652// --------------------------------------------------------------------------
2653//
2654void MStatusDisplay::PSToolsRange(TVirtualPS &vps, Float_t psw, Float_t psh) const
2655{
2656 if (vps.InheritsFrom(TPostScript::Class()))
2657 static_cast<TPostScript&>(vps).Range(psw, psh);
2658 // if (vps.InheritsFrom(TPDF::Class()))
2659 // static_cast<TPDF&>(vps).Range(psw*0.69, psh*0.69);
2660 // if (vps.InheritsFrom(TSVG::Class()))
2661 // static_cast<TSVG&>(vps).Range(psw, psh);
2662}
2663
2664// --------------------------------------------------------------------------
2665//
2666void MStatusDisplay::PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const
2667{
2668 if (vps.InheritsFrom(TPostScript::Class()))
2669 static_cast<TPostScript&>(vps).TextNDC(u, v, string);
2670 if (vps.InheritsFrom(TPDF::Class()))
2671 static_cast<TPDF&>(vps).TextNDC(u, v, string);
2672 // if (vps.InheritsFrom(TSVG::Class()))
2673 // static_cast<TSVG&>(vps).TextNDC(u, v, string);
2674}
2675
2676// --------------------------------------------------------------------------
2677//
2678Int_t MStatusDisplay::InitWriteDisplay(Int_t num, TString &name, const TString &ext)
2679{
2680 SetStatusLine1(MString::Format("Writing %s file...",ext.Data()));
2681 SetStatusLine2("Please be patient!");
2682
2683 if (!CheckTabForCanvas(num))
2684 {
2685 SetStatusLine2("Failed!");
2686 return 0;
2687 }
2688
2689 AddExtension(name, ext, num);
2690
2691 if (num<0)
2692 *fLog << inf << "Open " << ext << "-File: " << name << endl;
2693
2694 return num;
2695}
2696
2697// --------------------------------------------------------------------------
2698//
2699TCanvas *MStatusDisplay::InitWriteTab(Int_t num, TString &name)
2700{
2701 const Int_t i = TMath::Abs(num);
2702
2703 TCanvas *c = GetCanvas(i);
2704 if (!c)
2705 {
2706 if (num<0)
2707 *fLog << inf << " - ";
2708 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
2709 return 0;
2710 }
2711
2712 SetStatusLine2(MString::Format("Tab #%d", i));
2713
2714 //
2715 // Paint canvas into root file
2716 //
2717 if (num<0 && !name.IsNull())
2718 {
2719 Bool_t found = kFALSE;
2720 if (name.Index("%%%%name%%%%")>=0)
2721 {
2722 name.ReplaceAll("%%name%%", c->GetName());
2723 found = kTRUE;
2724 }
2725
2726 if (name.Index("%%%%title%%%%")>=0)
2727 {
2728 name.ReplaceAll("%%title%%", c->GetTitle());
2729 found = kTRUE;
2730 }
2731
2732 if (name.Index("%%%%tab%%%%")>=0)
2733 {
2734 name.ReplaceAll("%%tab%%", MString::Format("%d", i));
2735 found = kTRUE;
2736 }
2737
2738 if (!found)
2739 name.Insert(name.Last('.'), MString::Format("-%d", i));
2740 }
2741
2742 if (num<0)
2743 *fLog << inf << " - ";
2744 *fLog << inf << "Writing Tab #" << i;
2745
2746 if (!name.IsNull())
2747 *fLog << " to " << name;
2748
2749 *fLog << ": " << c->GetName() << "... " << flush;
2750
2751 return c;
2752}
2753
2754// This is a stupid workaround to get rid of the damned clipping
2755// of the text. Who the hell needs clipping?
2756class MyCanvas : public TCanvas
2757{
2758public:
2759 void Scale(Double_t val)
2760 {
2761 fAbsXlowNDC = -val;
2762 fAbsYlowNDC = -val;
2763 fAbsWNDC = 1+2*val;
2764 fAbsHNDC = 1+2*val;
2765 }
2766};
2767
2768// --------------------------------------------------------------------------
2769//
2770// Write some VGF (vector graphics format). Currently PS, PDF and SVG
2771// is available. Specified by ext.
2772//
2773// In case of num<0 all tabs are written into the VGF file. If num>0
2774// the canvas in the corresponding tab is written to the file.
2775// Name is the name of the file (with or without extension).
2776//
2777// Returns the number of pages written.
2778//
2779// To write all tabs you can also use SaveAsVGF(name, ext)
2780//
2781// If the third argument is given a bottom line is drawn with the text
2782// under it. If no argument is given a bottom line is drawn if
2783// fTitle (SetTitle) is not empty.
2784//
2785Int_t MStatusDisplay::SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext)
2786{
2787 num = InitWriteDisplay(num, name, ext);
2788 if (num==0)
2789 return 0;
2790
2791 TPad *padsav = (TPad*)gPad;
2792 TVirtualPS *psave = gVirtualPS;
2793
2794 TDatime d;
2795
2796 Int_t type = -1;
2797
2798 TVirtualPS *ps =0;
2799 if (!ext.CompareTo("ps", TString::kIgnoreCase))
2800 {
2801 gStyle->SetColorModelPS(1);
2802 ps = new TPostScript(name, 112);
2803 type = 1;
2804 }
2805 if (!ext.CompareTo("pdf", TString::kIgnoreCase))
2806 {
2807 ps = new TPDF(name, 112);
2808 type = 2;
2809 }
2810 if (!ext.CompareTo("svg", TString::kIgnoreCase))
2811 {
2812 ps = new TSVG(name, 112);
2813 type = 3;
2814 }
2815
2816 if (!ps)
2817 {
2818 *fLog << err << "Extension " << ext << " unknown..." << endl;
2819 SetStatusLine2("Failed!");
2820 return 0;
2821 }
2822
2823 ps->SetBit(TPad::kPrintingPS);
2824 if (type==1)
2825 ps->PrintFast(13, "/nan {1} def ");
2826
2827 gVirtualPS = ps;
2828
2829 //
2830 // Create some GUI elements for a page legend
2831 //
2832 TLine line;
2833
2834 int page = 1;
2835
2836 //
2837 // Maintain tab numbers
2838 //
2839 Int_t from, to;
2840 GetCanvasRange(from, to, num);
2841
2842 for (int i=from; i<to; i++)
2843 {
2844 TCanvas *c = InitWriteTab(num<0?-i:i);
2845 if (c==0)
2846 continue;
2847
2848 //
2849 // Init page and page size, make sure, that the canvas in the file
2850 // has the same Aspect Ratio than on the screen.
2851 //
2852 if (type==1 || i>from)
2853 ps->NewPage();
2854
2855 //
2856 // 28 is used here to scale the canvas into a height of 28,
2857 // such that the page title can be set above the canvas...
2858 //
2859 Float_t psw = 28.0; // A4 - width (29.7)
2860 Float_t psh = 21.0; // A4 - height (21.0)
2861
2862 const Float_t cw = c->GetWw();
2863 const Float_t ch = c->GetWh();
2864
2865 if (psw/psh>cw/ch)
2866 psw = cw/ch*psh;
2867 else
2868 psh = ch/cw*psw;
2869
2870 PSToolsRange(*ps, psw, psh);
2871
2872 //
2873 // Clone canvas and change background color and schedule for
2874 // deletion
2875 //
2876
2877 //const Bool_t store = c->IsBatch();
2878 //c->SetBatch(kTRUE);
2879 c->Paint();
2880 //c->SetBatch(store);
2881
2882 //
2883 // Change/fix the canvas coordinate system for the overlaying text.
2884 // This is necessary because root clip everything away which is
2885 // outside a predefined area, which is (0,0)/(1,1)
2886 //
2887 const Double_t height = 0.015; // Text height
2888 const Double_t off = 0.005; // Line offset from text
2889
2890 const Double_t bot = height+off;
2891 const Double_t top = 1-bot;
2892
2893 static_cast<MyCanvas*>(c)->Scale(bot);
2894
2895 // If gPad is not set to c all follwing commands will
2896 // get the wrong numbers for alignment
2897 gPad = c;
2898
2899 // Separator Lines
2900 line.PaintLineNDC(0.01, top, 0.99, top);
2901 line.PaintLineNDC(0.01, bot, 0.99, bot);
2902
2903 //
2904 // Print overlaying text (NDC = %)
2905 //
2906 // align phi col font size (11=left top)
2907 const TString txt(addon.IsNull() ? fTitle : addon);
2908
2909 // Text Attributes
2910 TAttText(11, 0, kBlack, 22, height).Copy(*ps);
2911
2912 // Text on top
2913 ps->SetTextAlign(11); // left bottom
2914 PSToolsTextNDC(*ps, 0.01, top+off, c->GetName());
2915
2916 ps->SetTextAlign(21); // cent bottom
2917 PSToolsTextNDC(*ps, 0.50, top+off, TString("MARS V"MARSVER" - Modular Analysis and Reconstruction Software - ")+d.AsString());
2918
2919 ps->SetTextAlign(31); // right bottom
2920 PSToolsTextNDC(*ps, 0.99, top+off, MString::Format("Page No.%i (%i)", page++, i));
2921
2922 // Text on bottom
2923 ps->SetTextAlign(13); // left top
2924 PSToolsTextNDC(*ps, 0.01, bot-off, c->GetTitle());
2925
2926 ps->SetTextAlign(23); // cent top
2927 PSToolsTextNDC(*ps, 0.50, bot-off, txt);
2928
2929 ps->SetTextAlign(33); // right top
2930 PSToolsTextNDC(*ps, 0.99, bot-off, MString::Format("(c) 2000-%d, Thomas Bretz", TDatime().GetYear()));
2931
2932 static_cast<MyCanvas*>(c)->Scale(0);
2933
2934 //
2935 // Finish drawing page
2936 //
2937 *fLog << "done." << endl;
2938 }
2939
2940 gPad = NULL; // Important!
2941
2942 ps->Close();
2943 delete ps;
2944
2945#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
2946 if (type==1)
2947 {
2948 SetStatusLine2("Updating header of PS file...");
2949
2950 if (num<0)
2951 *fLog << inf3 << " - Updating header of PS file... " << flush;
2952 UpdatePSHeader(name);
2953 if (num<0)
2954 *fLog << inf3 << "done." << endl;
2955 }
2956#endif
2957
2958 gVirtualPS = psave;
2959 if (padsav)
2960 padsav->cd();
2961
2962 if (num<0)
2963 *fLog << inf << "done." << endl;
2964
2965 SetStatusLine2(MString::Format("Done (%dpages)", page-1));
2966
2967 return page-1;
2968}
2969
2970// --------------------------------------------------------------------------
2971//
2972Bool_t MStatusDisplay::SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type)
2973{
2974#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
2975 if (gROOT->IsBatch())
2976 {
2977 *fLog << warn << "Sorry, writing image-files is not available in batch mode." << endl;
2978 return 0;
2979 }
2980#endif
2981
2982 TString ext;
2983 switch (type)
2984 {
2985 case TImage::kXpm:
2986 case TImage::kZCompressedXpm: ext = "xpm"; break;
2987 case TImage::kPng: ext = "png"; break;
2988 case TImage::kJpeg: ext = "jpg"; break;
2989 case TImage::kGif: ext = "gif"; break;
2990 case TImage::kTiff: ext = "tiff"; break;
2991 case TImage::kBmp: ext = "bmp"; break;
2992 case TImage::kXml: ext = "xml"; break;
2993 //case TImage::kGZCompressedXpm: ext = "xpm.gz"; break;
2994 //case TImage::kPpm: ext = "ppm"; break;
2995 //case TImage::kPnm: ext = "pnm"; break;
2996 //case TImage::kIco: ext = "ico"; break;
2997 //case TImage::kCur: ext = "cur"; break;
2998 //case TImage::kXcf: ext = "xcf"; break;
2999 //case TImage::kXbm: ext = "xbm"; break;
3000 //case TImage::kFits: ext = "fits"; break;
3001 //case TImage::kTga: ext = "tga"; break;
3002 default:
3003 *fLog << warn << "Sorry, unknown or unsupported file type..." << endl;
3004 return 0;
3005 }
3006
3007 num = InitWriteDisplay(num, name, ext);
3008 if (num==0)
3009 return 0;
3010
3011 TPad *padsav = (TPad*)gPad;
3012
3013 Int_t counter = 0;
3014
3015 //
3016 // Maintain tab numbers
3017 //
3018 Int_t from, to;
3019 GetCanvasRange(from, to, num);
3020
3021 for (int i=from; i<to; i++)
3022 {
3023 TString writename(name);
3024
3025 TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
3026 if (!c)
3027 continue;
3028
3029 //
3030 // Paint canvas into root file
3031 //
3032
3033 // TImage *img = TImage::Create();
3034 // img->FromPad(c);
3035 // img->WriteImage(writename, type);
3036 // delete img;
3037
3038 // FIXME: Not all file types are supported by Print()
3039 c->Print(writename);
3040
3041 if (num<0)
3042 *fLog << "done." << endl;
3043
3044 counter++;
3045 }
3046
3047 if (padsav)
3048 padsav->cd();
3049
3050 *fLog << inf << "done." << endl;
3051
3052 SetStatusLine2("Done.");
3053
3054 return counter>0;
3055}
3056
3057// --------------------------------------------------------------------------
3058//
3059Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
3060{
3061 num = InitWriteDisplay(num, name, "C");
3062 if (num==0)
3063 return kFALSE;
3064
3065 TPad *padsav = (TPad*)gPad;
3066
3067 Int_t counter = 0;
3068
3069 //
3070 // Maintain tab numbers
3071 //
3072 Int_t from, to;
3073 GetCanvasRange(from, to, num);
3074
3075 for (int i=from; i<to; i++)
3076 {
3077 TString writename(name);
3078
3079 TCanvas *c = InitWriteTab(num<0 ? -i : i, writename);
3080 if (!c)
3081 continue;
3082
3083 //
3084 // Clone canvas and change background color and schedule for
3085 // deletion
3086 //
3087 c->SaveSource(writename, "");
3088
3089 if (num<0)
3090 *fLog << "done." << endl;
3091
3092 counter++;
3093 }
3094
3095 if (padsav)
3096 padsav->cd();
3097
3098 *fLog << inf << "done." << endl;
3099
3100 SetStatusLine2("Done.");
3101
3102 return counter>0;
3103}
3104
3105// --------------------------------------------------------------------------
3106//
3107// In case of num<0 all tabs are written into a root file. As plain
3108// TCanvas objects if plain==kTRUE otherwise in a MStatusArray. If num>0
3109// the canvas in the corresponding tab is written to the file.
3110// Name is the name of the file (with or without extension).
3111//
3112// Returns the number of keys written.
3113//
3114// To write all tabs you can also use SaveAsRoot(name)
3115//
3116Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name, Bool_t plain)
3117{
3118 num = InitWriteDisplay(num, name, "root");
3119 if (num==0)
3120 return -1;
3121
3122 TFile *fsave = gFile;
3123 TFile file(name, "RECREATE", GetTitle(), 9);
3124 const Int_t keys = Write(num, "MStatusDisplay", plain ? "plain" : "");
3125 gFile = fsave;
3126
3127 SetStatusLine2("Done.");
3128
3129 return keys;
3130}
3131
3132// --------------------------------------------------------------------------
3133//
3134Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name, Char_t delim)
3135{
3136 num = InitWriteDisplay(num, name, "csv");
3137 if (num==0)
3138 return kFALSE;
3139
3140 gSystem->ExpandPathName(name);
3141
3142 ofstream fout(name);
3143 if (!fout)
3144 {
3145 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
3146 return kFALSE;
3147 }
3148
3149 fout << 0 << delim << GetName() << delim << GetTitle() << endl;
3150
3151 Int_t from, to;
3152 GetCanvasRange(from, to, num);
3153
3154 for (int i=from; i<to; i++)
3155 {
3156 TCanvas *c;
3157 if (!(c = GetCanvas(i)))
3158 {
3159 if (num<0)
3160 *fLog << inf << " - ";
3161 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
3162 continue;
3163 }
3164
3165 fout << i << delim << c->GetName() << delim << c->GetTitle() << endl;
3166 }
3167
3168 SetStatusLine2("Done.");
3169
3170 return kTRUE;
3171}
3172
3173/*
3174Bool_t MStatusDisplay::SaveAsCSV(Int_t num, TString name)
3175{
3176 num = InitWriteDisplay(num, name, "csv");
3177 if (num==0)
3178 return kFALSE;
3179
3180 gSystem->ExpandPathName(name);
3181
3182 ofstream fout(name);
3183 if (!fout)
3184 {
3185 *fLog << err << "Cannot open file " << name << ": " << strerror(errno) << endl;
3186 return kFALSE;
3187 }
3188
3189 fout << "<?xml version=\"1.0\"?>" << endl;
3190 fout << "<display name='" << GetName() << "'>" << endl;
3191 fout << " <file>" << name << "</file>" << endl;
3192 fout << " <status>" << endl;
3193 fout << " <name>" << GetName() << "</name>" << endl;
3194 fout << " <title>" << GetTitle() << "</title>" << endl;
3195 fout << " </status>" << endl;
3196 fout << " <tabs>" << endl;
3197
3198 fout << 0 << delim << GetName() << delim << GetTitle() << endl;
3199
3200 Int_t from, to;
3201 GetCanvasRange(from, to, num);
3202
3203 for (int i=from; i<to; i++)
3204 {
3205 TCanvas *c;
3206 if (!(c = GetCanvas(i)))
3207 {
3208 if (num<0)
3209 *fLog << inf << " - ";
3210 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
3211 continue;
3212 }
3213
3214 fout << " <tab index='" << i << "'>" << endl;
3215 fout << " <index>" << i << "</index>" << endl;
3216 fout << " <name>" << c->GetName() << "</name>" << endl;
3217 fout << " <title>" << c->GetName() << "</title>" << endl;
3218 fout << " </tab>" << endl;
3219 }
3220
3221 fout << " </tabs>" << endl;
3222 fout << "</display>" << endl;
3223
3224 SetStatusLine2("Done.");
3225
3226 return kTRUE;
3227}
3228*/
3229
3230// --------------------------------------------------------------------------
3231//
3232void MStatusDisplay::SaveAs(const char *c, const Option_t *o) const
3233{
3234#if ROOT_VERSION_CODE >= ROOT_VERSION(5,18,00)
3235 TGObject::SaveAs(c, o);
3236#endif
3237}
3238
3239// --------------------------------------------------------------------------
3240//
3241// Determin File type to save file as by extension. Allowed extensions are:
3242// root, ps, pdf, svg, gif, png, jpg, xpm, C
3243//
3244// returns -1 if file type is unknown. Otherwise return value of SaveAs*
3245//
3246Int_t MStatusDisplay::SaveAs(Int_t num, TString name)
3247{
3248 if (name.EndsWith(".root")) return SaveAsRoot(num, name); // kFileSaveAsRoot
3249 if (name.EndsWith(".ps")) return SaveAsPS(num, name); // kFileSaveAsPS
3250 if (name.EndsWith(".pdf")) return SaveAsPDF(num, name); // kFileSaveAsPDF
3251 if (name.EndsWith(".svg")) return SaveAsSVG(num, name); // kFileSaveAsSVG
3252 if (name.EndsWith(".gif")) return SaveAsGIF(num, name); // kFileSaveAsGIF
3253 if (name.EndsWith(".png")) return SaveAsPNG(num, name); // kFileSaveAsPNG
3254 if (name.EndsWith(".bmp")) return SaveAsBMP(num, name); // kFileSaveAsBMP
3255 if (name.EndsWith(".xml")) return SaveAsXML(num, name); // kFileSaveAsXML
3256 if (name.EndsWith(".jpg")) return SaveAsJPG(num, name); // kFileSaveAsJPG
3257 if (name.EndsWith(".xpm")) return SaveAsXPM(num, name); // kFileSaveAsXPM
3258 if (name.EndsWith(".csv")) return SaveAsCSV(num, name); // kFileSaveAsCSV
3259 if (name.EndsWith(".tiff")) return SaveAsTIFF(num, name); // kFileSaveAsTIFF
3260 if (name.EndsWith(".C")) return SaveAsC(num, name); // kFileSaveAsC
3261 return -1;
3262}
3263
3264// --------------------------------------------------------------------------
3265//
3266// Opens a save as dialog
3267//
3268Int_t MStatusDisplay::SaveAs(Int_t num)
3269{
3270 static const char *gSaveAsTypes[] =
3271 {
3272 "PostScript", "*.ps",
3273 "Acrobat pdf", "*.pdf",
3274 "SVG vector", "*.svg",
3275 "Gif files", "*.gif",
3276 "Png files", "*.png",
3277 "Gif files", "*.gif",
3278 "Jpeg files", "*.jpeg",
3279 "Xpm files", "*.xpm",
3280 "Bmp files", "*.bmp",
3281 "Xml files", "*.xml",
3282 "Tiff files", "*.tiff",
3283 "Csv files", "*.csv",
3284 "Macro files", "*.C",
3285 "ROOT files", "*.root",
3286 "All files", "*",
3287 NULL, NULL
3288 };
3289
3290 static TString dir(".");
3291
3292 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
3293
3294 fi.fFileTypes = (const char**)gSaveAsTypes;
3295 fi.fIniDir = StrDup(dir);
3296
3297 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
3298
3299 if (!fi.fFilename)
3300 return 0;
3301
3302 dir = fi.fIniDir;
3303
3304 const Int_t rc = SaveAs(num, fi.fFilename);
3305 if (rc>=0)
3306 return rc;
3307
3308 Warning("MStatusDisplay::SaveAs", "Unknown Extension: %s", fi.fFilename);
3309 return 0;
3310}
3311
3312// --------------------------------------------------------------------------
3313//
3314// Open contents of a MStatusDisplay with key name from file fname.
3315//
3316Int_t MStatusDisplay::Open(TString fname, const char *name)
3317{
3318 TFile file(fname, "READ");
3319 if (file.IsZombie())
3320 {
3321 gLog << warn << "WARNING - Cannot open file " << fname << endl;
3322 return 0;
3323 }
3324
3325 return Read(name);
3326}
3327
3328// --------------------------------------------------------------------------
3329//
3330// Opens an open dialog
3331//
3332Int_t MStatusDisplay::Open()
3333{
3334 static const char *gOpenTypes[] =
3335 {
3336 "ROOT files", "*.root",
3337 "All files", "*",
3338 NULL, NULL
3339 };
3340
3341 static TString dir(".");
3342
3343 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
3344
3345 fi.fFileTypes = (const char**)gOpenTypes;
3346 fi.fIniDir = StrDup(dir);
3347
3348 new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
3349
3350 if (!fi.fFilename)
3351 return 0;
3352
3353 dir = fi.fIniDir;
3354
3355 return Open(fi.fFilename);
3356}
3357
3358// --------------------------------------------------------------------------
3359//
3360// Change width of display. The height is calculated accordingly.
3361//
3362void MStatusDisplay::SetDisplayWidth(UInt_t dw)
3363{
3364 if (gROOT->IsBatch())
3365 {
3366 SetCanvasWidth(dw);
3367 return;
3368 }
3369
3370 // 4 == 2*default border with of canvas
3371 dw -= 4;
3372
3373 // Difference between canvas size and display size
3374 const UInt_t cw = GetWidth() -fTab->GetWidth();
3375 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3376
3377 const UInt_t dh = TMath::Nint((dw - cw)/1.5 + ch);
3378
3379 Resize(dw, dh); // Set display size
3380}
3381
3382// --------------------------------------------------------------------------
3383//
3384// Change height of display. The width is calculated accordingly.
3385//
3386void MStatusDisplay::SetDisplayHeight(UInt_t dh)
3387{
3388 if (gROOT->IsBatch())
3389 {
3390 SetCanvasHeight(dh);
3391 return;
3392 }
3393
3394 // 4 == 2*default border with of canvas
3395 dh -= 4;
3396
3397 // Difference between canvas size and display size
3398 const UInt_t cw = GetWidth() -fTab->GetWidth();
3399 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3400
3401 const UInt_t dw = TMath::Nint((dh - ch)*1.5 + cw);
3402
3403 Resize(dw, dh); // Set display size
3404}
3405
3406// --------------------------------------------------------------------------
3407//
3408// Change width of canvas. The height is calculated accordingly.
3409//
3410void MStatusDisplay::SetCanvasWidth(UInt_t w)
3411{
3412 // 4 == 2*default border with of canvas
3413 w += 4;
3414
3415 if (gROOT->IsBatch())
3416 {
3417 Resize(w, 3*w/2);
3418 return;
3419 }
3420
3421 // Difference between canvas size and display size
3422 const UInt_t cw = GetWidth() -fTab->GetWidth();
3423 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3424
3425 const UInt_t h = TMath::Nint(w/1.5 + ch);
3426
3427 Resize(w + cw, h); // Set display size
3428}
3429
3430// --------------------------------------------------------------------------
3431//
3432// Change height of canvas. The width is calculated accordingly.
3433//
3434void MStatusDisplay::SetCanvasHeight(UInt_t h)
3435{
3436 // 4 == 2*default border with of canvas
3437 h += 4;
3438
3439 if (gROOT->IsBatch())
3440 {
3441 Resize(2*h/3, h);
3442 return;
3443 }
3444
3445 // Difference between canvas size and display size
3446 const UInt_t cw = GetWidth() -fTab->GetWidth();
3447 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3448
3449 // 4 == 2*default border with of canvas
3450 const UInt_t dw = TMath::Nint((h+4)*1.5 + cw);
3451
3452 Resize(dw, h + ch); // Set display size
3453}
3454
3455// --------------------------------------------------------------------------
3456//
3457// Calculate width and height of the display such that it fits into the
3458// defined box.
3459//
3460void MStatusDisplay::SetDisplaySize(UInt_t w, UInt_t h)
3461{
3462 if (gROOT->IsBatch())
3463 return;
3464
3465 SetDisplayHeight(h);
3466
3467 if (GetWidth()>w)
3468 SetDisplayWidth(w);
3469}
3470
3471// --------------------------------------------------------------------------
3472//
3473// Calculate an optimum size for the display from the desktop size
3474//
3475void MStatusDisplay::SetOptimumSize()
3476{
3477 if (gROOT->IsBatch())
3478 return;
3479
3480 const UInt_t w = TMath::Nint(0.95*gClient->GetDisplayWidth());
3481 const UInt_t h = TMath::Nint(0.95*gClient->GetDisplayHeight());
3482
3483 SetDisplaySize(w, h);
3484}
3485
3486
3487Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
3488{
3489 //
3490 // The initialization of the GUI is not yet enough finished...
3491 //
3492 if (!fTab)
3493 return kTRUE;
3494
3495 UInt_t w = evt->fWidth;
3496 UInt_t h = evt->fHeight;
3497
3498 const Bool_t wchanged = w!=GetWidth()-fTab->GetWidth();
3499 const Bool_t hchanged = h!=GetHeight()-fTab->GetHeight();
3500
3501 if (!wchanged && !hchanged)
3502 {
3503 Layout();
3504 // FIXME: Make sure that this doesn't result in endless loops.
3505 return kTRUE;
3506 }
3507
3508 if (GetWidth()==1 && GetHeight()==1)
3509 return kTRUE;
3510
3511 // calculate the constant part of the window
3512 const UInt_t cw = GetWidth() -fTab->GetWidth();
3513 const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
3514
3515 // calculate new size of frame (canvas @ 2:3)
3516 if (hchanged)
3517 w = TMath::Nint((h-ch)*1.5+cw);
3518 else
3519 h = TMath::Nint((w-cw)/1.5+ch);
3520
3521 // resize frame
3522 Resize(w, h);
3523
3524 return kTRUE;
3525}
3526
3527Bool_t MStatusDisplay::HandleEvent(Event_t *event)
3528{
3529 // Instead of doing this in CloseWindow (called from HandleEvent)
3530 // we do it here. This makes sure, that handle event doesn't
3531 // execute code after deleting this.
3532 if (event->fType==kDestroyNotify)
3533 {
3534 if (Close())
3535 delete this;
3536// Close();
3537 return kTRUE;
3538 }
3539
3540 const Bool_t rc = TGMainFrame::HandleEvent(event);
3541
3542 //
3543 // This fixes a bug in older root versions which makes
3544 // TCanvas crash if gPad==NULL. So we make sure, that
3545 // gPad!=NULL -- be carfull, this may have other side
3546 // effects.
3547 //
3548#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
3549 if (!gPad && fTab)
3550 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
3551 {
3552 TCanvas *c = GetCanvas(i);
3553 if (c)
3554 {
3555 c->cd();
3556 gLog << dbg << "MStatusDisplay::HandleEvent - Workaround: gPad=" << gPad << "." << endl;
3557 break;
3558 }
3559 }
3560#endif
3561
3562 return rc;
3563}
Note: See TracBrowser for help on using the repository browser.