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

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