source: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc@ 2893

Last change on this file since 2893 was 2893, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 63.8 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
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() or SaveAsC().
34// Direct printing to the default printer (via lpr) can be done by
35// PrintToLpr().
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 <fstream> // fstream
64
65#include <TLine.h> // TLine
66#include <TText.h> // TText
67#include <TFile.h> // gFile
68#include <TFrame.h> // TFrame
69#include <TStyle.h> // gStyle
70#include <TCanvas.h> // TCanvas
71#include <TSystem.h> // gSystem
72#include <TDatime.h> // TDatime
73#include <TRandom.h> // TRandom
74#include <TThread.h> // TThread::Self()
75#include <TBrowser.h> // TBrowser
76#include <TObjArray.h> // TObjArray
77#include <TPostScript.h> // TPostScript
78#include <TMethodCall.h> // TMethodCall
79
80//#include <TRint.h> // gApplication, TRint::Class()
81#include <TInterpreter.h> // gInterpreter
82
83#include <TGTab.h> // TGTab
84#include <TGLabel.h> // TGLabel
85#include <TG3DLine.h> // TGHorizontal3DLine
86#include <TGButton.h> // TGPictureButton
87#include <TGTextView.h> // TGTextView
88#include <TGStatusBar.h> // TGStatusBar
89#include <TGFileDialog.h> // TGFileDialog
90#include <TGProgressBar.h> // TGHProgressBar
91#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
92
93#include "MLog.h" // MLog
94#include "MLogManip.h" // inf, warn, err
95
96#include "MGList.h" // MGList
97#include "MGMenu.h" // MGMenu, TGMenu
98#include "MSearch.h" // MSearch
99#include "MParContainer.h" // MParContainer::GetDescriptor
100
101#undef DEBUG
102//#define DEBUG
103
104ClassImp(MStatusDisplay);
105
106using namespace std;
107
108// ------------ Workaround for a non working TGTextView::Search -------------
109#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,05)
110class MGTextView : public TGTextView
111{
112public:
113 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, Int_t id = -1,
114 UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
115 TGTextView(parent, w, h, id, sboptions, back) {}
116 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
117 Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
118 TGTextView(parent, w, h, text, id, sboptions, back) {}
119 MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
120 Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
121 TGTextView(parent, w, h, string, id, sboptions, back) {}
122
123 void Mark(Long_t xPos, Long_t yPos) { TGTextView::Mark(xPos, yPos); }
124 void UnMark() { TGTextView::UnMark(); }
125
126 Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive)
127 {
128 // Taken from TGTextView::Search and modified.
129
130 TGLongPosition pos, pos2;
131 pos2.fX = pos2.fY = 0;
132 if (fIsMarked) {
133 if (!direction)
134 {
135 pos2.fX = fMarkedStart.fX;
136 pos2.fY = fMarkedStart.fY;
137 }
138 else
139 {
140 pos2.fX = fMarkedEnd.fX + 1;
141 pos2.fY = fMarkedEnd.fY;
142 }
143 }
144 if (!fText->Search(&pos, pos2, string, direction, caseSensitive))
145 return kFALSE;
146 UnMark();
147 fIsMarked = kTRUE;
148 fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
149 fMarkedStart.fX = pos.fX;
150 fMarkedEnd.fX = fMarkedStart.fX + strlen(string);
151 pos.fY = ToObjYCoord(fVisible.fY);
152 if ((fMarkedStart.fY < pos.fY) ||
153 (ToScrYCoord(fMarkedStart.fY) >= (Int_t)fCanvas->GetHeight()))
154 pos.fY = fMarkedStart.fY;
155 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
156 if ((fMarkedStart.fX < pos.fX) ||
157 (ToScrXCoord(fMarkedStart.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()))
158 pos.fX = fMarkedStart.fX;
159
160 SetVsbPosition((ToScrYCoord(pos.fY) + fVisible.fY)/fScrollVal.fY);
161 SetHsbPosition((ToScrXCoord(pos.fX, pos.fY) + fVisible.fX)/fScrollVal.fX);
162 DrawRegion(0, (Int_t)ToScrYCoord(fMarkedStart.fY), fCanvas->GetWidth(),
163 UInt_t(ToScrYCoord(fMarkedEnd.fY+1) - ToScrYCoord(fMarkedEnd.fY)));
164
165 return kTRUE;
166 }
167};
168#else
169#define MGTextView TGTextView
170#endif
171// --------------------------------------------------------------------------
172
173// --------------------------------------------------------------------------
174//
175// Add menu bar to the GUI
176//
177void MStatusDisplay::AddMenuBar()
178{
179 //
180 // File Menu
181 //
182 MGPopupMenu *filemenu = new MGPopupMenu(gClient->GetRoot());
183 // filemenu->AddEntry("Save &As...", kFileSaveAs);
184 filemenu->AddEntry("New Can&vas", kFileCanvas);
185 filemenu->AddEntry("New &Browser", kFileBrowser);
186 filemenu->AddSeparator();
187 filemenu->AddEntry("Save As status.&ps", kFileSaveAsPS);
188 filemenu->AddEntry("Save As status.&gif", kFileSaveAsGIF);
189 filemenu->AddEntry("Save As status.&C", kFileSaveAsC);
190 filemenu->AddEntry("Save As status.&root", kFileSaveAsRoot);
191 filemenu->AddSeparator();
192 filemenu->AddEntry("&Open...", kFileOpen);
193 filemenu->AddEntry("Save &As...", kFileSaveAs);
194 filemenu->AddSeparator();
195 filemenu->AddEntry("Re&set", kFileReset);
196 filemenu->AddSeparator();
197 filemenu->AddEntry("Print with &lpr", kFilePrint);
198 //filemenu->AddEntry("Set printer &name", kFilePrinterName);
199 filemenu->AddSeparator();
200 filemenu->AddEntry("C&lose", kFileClose);
201 filemenu->AddEntry("E&xit", kFileExit);
202 filemenu->Associate(this);
203
204 //
205 // Tab Menu
206 //
207 MGPopupMenu *tabmenu = new MGPopupMenu(gClient->GetRoot());
208 tabmenu->AddEntry("Next [&+]", kTabNext);
209 tabmenu->AddEntry("Previous [&-]", kTabPrevious);
210 tabmenu->AddSeparator();
211 tabmenu->AddEntry("Save As tab-i.&ps", kTabSaveAsPS);
212 tabmenu->AddEntry("Save As tab-i.&gif", kTabSaveAsGIF);
213 tabmenu->AddEntry("Save As tab-i.&C", kTabSaveAsC);
214 tabmenu->AddEntry("Save As tab-i.&root", kTabSaveAsRoot);
215 tabmenu->AddSeparator();
216 tabmenu->AddEntry("Save &As...", kTabSaveAs);
217 tabmenu->AddSeparator();
218 tabmenu->AddEntry("Re&move", kTabRemove);
219 tabmenu->AddSeparator();
220 tabmenu->AddEntry("Print with &lpr", kTabPrint);
221 tabmenu->Associate(this);
222
223 //
224 // Loop Menu
225 //
226 MGPopupMenu *loopmenu = new MGPopupMenu(gClient->GetRoot());
227 loopmenu->AddEntry("&Stop", kLoopStop);
228 loopmenu->Associate(this);
229
230 //
231 // Loop Menu
232 //
233 MGPopupMenu *sizemenu = new MGPopupMenu(gClient->GetRoot());
234 sizemenu->AddEntry("Fit to 640x&480", kSize640);
235 sizemenu->AddEntry("Fit to 800x&600", kSize800);
236 sizemenu->AddEntry("Fit to 960x7&20", kSize960);
237 sizemenu->AddEntry("Fit to 1024x&768", kSize1024);
238 sizemenu->AddEntry("Fit to 1280x&1024", kSize1280);
239 sizemenu->Associate(this);
240
241 //
242 // Log Menu
243 //
244 MGPopupMenu *logmenu = new MGPopupMenu(gClient->GetRoot());
245 logmenu->AddEntry("&Copy Selected", kLogCopy);
246 logmenu->AddEntry("Cl&ear all", kLogClear);
247 logmenu->AddSeparator();
248 logmenu->AddEntry("Select &All", kLogSelect);
249 logmenu->AddSeparator();
250 logmenu->AddEntry("&Find...", kLogFind);
251 logmenu->AddSeparator();
252 logmenu->AddEntry("&Save", kLogSave);
253 logmenu->AddEntry("Save &append", kLogAppend);
254 logmenu->Associate(this);
255
256 //
257 // Menu Bar
258 //
259 TGLayoutHints *layitem = new TGLayoutHints(kLHintsNormal, 0, 4, 0, 0);
260 fList->Add(layitem);
261
262 MGMenuBar *menubar = new MGMenuBar(this, 1, 1, kHorizontalFrame);
263 menubar->AddPopup("&File", filemenu, layitem);
264 menubar->AddPopup("Lo&g", logmenu, layitem);
265 menubar->AddPopup("&Size", sizemenu, layitem);
266 menubar->AddPopup("&Tab", tabmenu, layitem);
267 menubar->AddPopup("&Loop", loopmenu, layitem);
268 menubar->BindKeys(this);
269 AddFrame(menubar);
270
271 //
272 // Line below menu bar
273 //
274 TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
275 fList->Add(laylinesep);
276
277 TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
278 AddFrame(linesep, laylinesep);
279
280 //
281 // Add everything to autodel list
282 //
283 fList->Add(filemenu);
284 fList->Add(loopmenu);
285 fList->Add(sizemenu);
286 fList->Add(menubar);
287 fList->Add(tabmenu);
288 fList->Add(logmenu);
289 fList->Add(linesep);
290}
291
292// --------------------------------------------------------------------------
293//
294// Adds an empty TGCompositeFrame which might be filled by the user
295//
296void MStatusDisplay::AddUserFrame()
297{
298 TGLayoutHints *lay=new TGLayoutHints(kLHintsExpandX);
299 fList->Add(lay);
300
301 fUserFrame = new TGCompositeFrame(this, 1, 1);
302 AddFrame(fUserFrame, lay);
303 fList->Add(fUserFrame);
304}
305
306// --------------------------------------------------------------------------
307//
308// Add the title tab
309//
310void MStatusDisplay::AddMarsTab()
311{
312 // Create Tab1
313 TGCompositeFrame *f = fTab->AddTab("-=MARS=-");
314
315 // Add MARS version
316 TGLabel *l = new TGLabel(f, Form("Official Release: V%s", MARSVER));
317 fList->Add(l);
318
319 TGLayoutHints *layb = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 5, 5);
320 fList->Add(layb);
321 f->AddFrame(l, layb);
322
323 // Add root version
324 l = new TGLabel(f, Form("Using ROOT v%s", ROOTVER));
325 fList->Add(l);
326
327 TGLayoutHints *lay = new TGLayoutHints(kLHintsCenterX|kLHintsTop);
328 fList->Add(lay);
329 f->AddFrame(l, lay);
330
331 // Add Mars logo picture
332 const TGPicture *pic2 = fList->GetPicture("marslogo.xpm");
333 if (pic2)
334 {
335 TGPictureButton *mars = new TGPictureButton(f, pic2, kPicMars);
336 fList->Add(mars);
337 mars->Associate(this);
338
339 TGLayoutHints *lay2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 10, 10, 5, 5);
340 fList->Add(lay2);
341 f->AddFrame(mars, lay2);
342 }
343
344 // Add date and time
345 TDatime d;
346 l = new TGLabel(f, d.AsString());
347 fList->Add(l);
348 f->AddFrame(l, lay);
349
350 // Add copyright notice
351 l = new TGLabel(f, "(c) MAGIC Software Development, 2000-2003");
352 fList->Add(l);
353 f->AddFrame(l, layb);
354
355 TGLayoutHints *layc = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 0, 5);
356 fList->Add(layc);
357
358 l = new TGLabel(f, "<< Thomas Bretz >>");
359 fList->Add(l);
360 f->AddFrame(l, layc);
361}
362
363// --------------------------------------------------------------------------
364//
365// Adds the logbook tab to the GUI if it was not added previously.
366//
367// The logbook is updated four times a second only if the tab is visible.
368//
369// You can redirect an output to a MLog-logstream by calling SetLogStream().
370// To disable redirction call SetLogStream(NULL)
371//
372// if enable==kFALSE the stdout is disabled/enabled. Otherwise stdout
373// is ignored.
374//
375void MStatusDisplay::SetLogStream(MLog *log, Bool_t enable)
376{
377 if (gROOT->IsBatch())
378 return;
379
380 if (log && fLogBox==NULL)
381 {
382 fLogIdx = fTab->GetNumberOfTabs();
383
384 // Create Tab1
385 TGCompositeFrame *f = fTab->AddTab("-Logbook-");
386
387 // Create Text View
388 fLogBox = new MGTextView(f, 1, 1); // , -1, 0, TGFrame::GetDefaultFrameBackground());
389 if (fFont)
390 fLogBox->SetFont(fFont);
391 //fLogBox->Associate(this);
392
393 // Add List box to the tab
394 TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY,2,2,2,2);
395 f->AddFrame(fLogBox, lay);
396
397 // layout and map tab
398 Layout();
399 MapSubwindows();
400
401 // make it visible
402 // FIXME: This is a workaround, because TApplication::Run is not
403 // thread safe against ProcessEvents. We assume, that if
404 // we are not in the Main-Thread ProcessEvents() is
405 // called by the TApplication Event Loop...
406 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
407 gClient->ProcessEventsFor(fTab);
408 }
409
410 if (log)
411 {
412 fLog = log;
413
414 log->SetOutputGui(fLogBox, kTRUE);
415 log->EnableOutputDevice(MLog::eGui);
416 if (!enable)
417 log->DisableOutputDevice(MLog::eStdout);
418
419 fLogTimer.Start();
420 }
421 else
422 {
423 fLogTimer.Stop();
424
425 fLog->DisableOutputDevice(MLog::eGui);
426 fLog->SetOutputGui(NULL);
427 if (!enable)
428 fLog->EnableOutputDevice(MLog::eStdout);
429
430 fLog = &gLog;
431 }
432}
433
434// --------------------------------------------------------------------------
435//
436// Add the Tabs and the predifined Tabs to the GUI
437//
438void MStatusDisplay::AddTabs()
439{
440 fTab = new TGTab(this, 300, 300);
441
442 AddMarsTab();
443
444 // Add fTab to Frame
445 TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 5, 5, 5);
446 AddFrame(fTab, laytabs);
447
448 fList->Add(fTab);
449 fList->Add(laytabs);
450}
451
452// --------------------------------------------------------------------------
453//
454// Add the progress bar to the GUI. The Progress Bar range is set to
455// (0,1) as default.
456//
457void MStatusDisplay::AddProgressBar()
458{
459 TGLayoutHints *laybar=new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5);
460 fList->Add(laybar);
461
462 fBar=new TGHProgressBar(this);
463 fBar->SetRange(0, 1);
464 fBar->ShowPosition();
465 AddFrame(fBar, laybar);
466 fList->Add(fBar);
467}
468
469// --------------------------------------------------------------------------
470//
471// Set the progress bar position between 0 and 1. The Progress bar range
472// is assumed to be (0,1)
473//
474void MStatusDisplay::SetProgressBarPosition(Float_t p)
475{
476 fBar->SetPosition(p);
477}
478
479// --------------------------------------------------------------------------
480//
481// Adds the status bar to the GUI
482//
483void MStatusDisplay::AddStatusBar()
484{
485 fStatusBar = new TGStatusBar(this, 1, 1);
486
487 //
488 // Divide it like the 'Golden Cut' (goldener Schnitt)
489 //
490 // 1-a a
491 // 1: ------|----
492 //
493 // a/(1-a) = (1-a)/1
494 // a^2+a-1 = 0
495 // a = (-1+-sqrt(1+4))/2 = sqrt(5)/2-1/2 = 0.618
496 //
497 Int_t p[2] = {38, 62};
498
499 fStatusBar->SetParts(p, 2);
500
501 TGLayoutHints *layb = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 4, 0, 3);
502 AddFrame(fStatusBar, layb);
503
504 fList->Add(fStatusBar);
505 fList->Add(layb);
506}
507
508// --------------------------------------------------------------------------
509//
510// Change the text in the status line 1
511//
512void MStatusDisplay::SetStatusLine1(const char *txt)
513{
514 if (gROOT->IsBatch())
515 return;
516 fStatusBar->SetText(txt, 0);
517
518 // FIXME: This is a workaround, because TApplication::Run is not
519 // thread safe against ProcessEvents. We assume, that if
520 // we are not in the Main-Thread ProcessEvents() is
521 // called by the TApplication Event Loop...
522 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
523 gClient->ProcessEventsFor(fStatusBar);
524}
525
526// --------------------------------------------------------------------------
527//
528// Change the text in the status line 2
529//
530void MStatusDisplay::SetStatusLine2(const char *txt)
531{
532 if (gROOT->IsBatch())
533 return;
534 fStatusBar->SetText(txt, 1);
535
536 // FIXME: This is a workaround, because TApplication::Run is not
537 // thread safe against ProcessEvents. We assume, that if
538 // we are not in the Main-Thread ProcessEvents() is
539 // called by the TApplication Event Loop...
540 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
541 gClient->ProcessEventsFor(fStatusBar);
542}
543
544// --------------------------------------------------------------------------
545//
546// Display information about the name of a container
547//
548void MStatusDisplay::SetStatusLine2(const MParContainer &cont)
549{
550 SetStatusLine2(Form("%s: %s", cont.GetDescriptor(), cont.GetTitle()));
551}
552
553// --------------------------------------------------------------------------
554//
555// Default constructor. Opens a window with a progress bar. Get a pointer
556// to the bar by calling GetBar. This pointer can be used for the
557// eventloop.
558//
559// Be carefull: killing or closing the window while the progress meter
560// is still in use may cause segmentation faults. Please kill the window
561// always by deleting the corresponding object.
562//
563// Update time default: 10s
564//
565MStatusDisplay::MStatusDisplay(Long_t t)
566: TGMainFrame(NULL, 1, 1), fName("MStatusDisplay"), fLog(&gLog), fTab(NULL), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0)
567{
568 // p==NULL means: Take gClient->GetRoot() if not in batch mode
569 // see TGWindow::TGWindow()
570
571 //
572 // This is a possibility for the user to check whether this
573 // object has already been deleted. It will be removed
574 // from the list in the destructor.
575 //
576 gROOT->GetListOfSpecials()->Add(this);
577
578 fFont = gVirtualX->LoadQueryFont("7x13bold");
579 fMutex = new TMutex;
580
581 //
582 // In case we are in batch mode use a list of canvases
583 // instead of the Root Embedded Canvases in the TGTab
584 //
585 fBatch = new TList;
586 fBatch->SetOwner();
587
588 //
589 // Create a list handling GUI widgets
590 //
591 fList = new MGList;
592 fList->SetOwner();
593
594 //
595 // Create the layout hint for the root embedded canavses
596 //
597 fLayCanvas = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
598 fList->Add(fLayCanvas);
599
600 //
601 // Add Widgets (from top to bottom)
602 //
603 if (gClient) // BATCH MODE
604 {
605 AddMenuBar();
606 AddUserFrame();
607 AddTabs();
608 AddProgressBar();
609 AddStatusBar();
610 }
611
612 //
613 // set the smallest and biggest size of the Main frame
614 // and move it to its appearance position
615 SetWMSizeHints(570, 480, 1280, 980, 1, 1);
616 MoveResize(rand()%100+570, rand()%100+480, 570, 480);
617
618 //
619 // Now do an automatic layout of the widgets and display the window
620 //
621 Layout();
622 MapSubwindows();
623
624 SetWindowName("Status Display");
625 SetIconName("Status Display");
626
627 MapWindow();
628
629 // FIXME: This is a workaround, because TApplication::Run is not
630 // thread safe against ProcessEvents. We assume, that if
631 // we are not in the Main-Thread ProcessEvents() is
632 // called by the TApplication Event Loop...
633 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
634 gSystem->ProcessEvents();
635}
636
637// --------------------------------------------------------------------------
638//
639// Destruct the window with all its tiles. Also the Progress Bar object
640// is deleted.
641//
642MStatusDisplay::~MStatusDisplay()
643{
644#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
645 fTab = NULL; // See HandleEvent
646#endif
647
648 //
649 // Delete object from global object table so it cannot
650 // be deleted by chance a second time
651 //
652 gInterpreter->DeleteGlobal(this);
653
654 //
655 // This is a possibility for the user to check whether this
656 // object has already been deleted. It has been added
657 // to the list in the constructor.
658 //
659 gROOT->GetListOfSpecials()->Remove(this);
660
661 SetLogStream(NULL);
662
663 //
664 // Delete the list of objects corresponding to this object
665 //
666 delete fList;
667
668 //
669 // Delete the list list of canvases used in batch mode
670 // instead of the Root Embedded Canvases in the TGTab
671 //
672 delete fBatch;
673
674 //
675 // Delete the font used for the logging window
676 //
677 if (fFont)
678 gVirtualX->DeleteFont(fFont);
679
680 //
681 // Delete mutex
682 //
683 delete fMutex;
684}
685
686// --------------------------------------------------------------------------
687//
688// Takes a TGCompositeFrame as argument. Searches for the first
689// TRootEmbeddedCanvas which is contained by it and returns a pointer
690// to the corresponding TCanvas. If it isn't found NULL is returned.
691//
692TRootEmbeddedCanvas *MStatusDisplay::GetEmbeddedCanvas(TGCompositeFrame *cf) const
693{
694 TIter Next(cf->GetList());
695
696 TGFrameElement *f;
697 while ((f=(TGFrameElement*)Next()))
698 if (f->fFrame->InheritsFrom(TRootEmbeddedCanvas::Class()))
699 return (TRootEmbeddedCanvas*)f->fFrame;
700
701 return NULL;
702}
703
704// --------------------------------------------------------------------------
705//
706// Takes a TGCompositeFrame as argument. Searches for the first
707// TRootEmbeddedCanvas which is contained by it and returns a pointer
708// to the corresponding TCanvas. If it isn't found NULL is returned.
709//
710TCanvas *MStatusDisplay::GetCanvas(TGCompositeFrame *cf) const
711{
712 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(cf);
713 return ec ? ec->GetCanvas() : NULL;
714}
715
716// --------------------------------------------------------------------------
717//
718// Returns GetCanvas of the i-th Tab.
719//
720TCanvas *MStatusDisplay::GetCanvas(int i) const
721{
722 if (gROOT->IsBatch())
723 return (TCanvas*)fBatch->At(i-1);
724
725 if (i<0 || i>=fTab->GetNumberOfTabs())
726 {
727 *fLog << warn << "MStatusDisplay::GetCanvas: Out of range." << endl;
728 return NULL;
729 }
730
731 return GetCanvas(fTab->GetTabContainer(i));
732}
733
734// --------------------------------------------------------------------------
735//
736// Searches for a TRootEmbeddedCanvas in the TGCompositeFramme of the
737// Tab with the name 'name'. Returns the corresponding TCanvas or
738// NULL if something isn't found.
739//
740TCanvas *MStatusDisplay::GetCanvas(const TString &name) const
741{
742 TGFrameElement *f;
743 TIter Next(fTab->GetList());
744 while ((f=(TGFrameElement*)Next()))
745 {
746 TObject *frame = f->fFrame;
747 if (!frame->InheritsFrom(TGTabElement::Class()))
748 continue;
749
750 TGTabElement *tab = (TGTabElement*)frame;
751 if (tab->GetString()==name)
752 break;
753 }
754
755 // Search for the next TGCompositeFrame in the list
756 while ((f=(TGFrameElement*)Next()))
757 {
758 TObject *frame = f->fFrame;
759 if (frame->InheritsFrom(TGCompositeFrame::Class()))
760 return GetCanvas((TGCompositeFrame*)frame);
761 }
762
763 return NULL;
764}
765
766// --------------------------------------------------------------------------
767//
768// Calls TCanvas::cd(), for the canvas returned by GetCanvas.
769//
770Bool_t MStatusDisplay::CdCanvas(const TString &name)
771{
772 TCanvas *c = GetCanvas(name);
773 if (!c)
774 return kFALSE;
775
776 c->cd();
777 return kTRUE;
778}
779
780TGCompositeFrame *MStatusDisplay::AddRawTab(const char *name)
781{
782 // Add new tab
783 TGCompositeFrame *f = fTab->AddTab(name);
784
785 // layout and map new tab
786 Layout();
787 MapSubwindows();
788 Layout();
789
790 // display new tab in the main frame
791 // FIXME: This is a workaround, because TApplication::Run is not
792 // thread safe against ProcessEvents. We assume, that if
793 // we are not in the Main-Thread ProcessEvents() is
794 // called by the TApplication Event Loop...
795 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
796 gClient->ProcessEventsFor(fTab);
797
798 *fLog << inf << "Adding Raw Tab '" << name << "' (" << f->GetWidth() << "x";
799 *fLog << f->GetHeight() << ")" << endl;
800
801 // return pointer to new canvas
802 return f;
803}
804
805// --------------------------------------------------------------------------
806//
807// Adds a new tab with the name 'name'. Adds a TRootEmbeddedCanvas to the
808// tab and returns a reference to the corresponding TCanvas.
809//
810TCanvas &MStatusDisplay::AddTab(const char *name)
811{
812 if (gROOT->IsBatch())
813 {
814 TCanvas *c = new TCanvas(name, name);
815 fBatch->Add(c);
816 return *c;
817 }
818
819 // Add new tab
820 TGCompositeFrame *f = fTab->AddTab(name);
821
822 // create root embedded canvas and add it to the tab
823 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, f->GetWidth(), f->GetHeight(), 0);
824 f->AddFrame(ec, fLayCanvas);
825 fList->Add(ec);
826
827 // set background and border mode of the canvas
828 TCanvas &c = *ec->GetCanvas();
829
830 c.SetFillColor(16/*165*//*17*//*203*/);
831 c.SetBorderMode(0);
832
833 // If kNoContextMenu set set kNoContextMenu of the canvas
834 if (TestBit(kNoContextMenu))
835 c.SetBit(kNoContextMenu);
836
837 // layout and map new tab
838 Layout(); // seems to layout the TGCompositeFrame
839 MapSubwindows(); // maps the TGCompositeFrame
840 Layout(); // layout the embedded canvas in the frame
841
842 // display new tab in the main frame
843 // FIXME: This is a workaround, because TApplication::Run is not
844 // thread safe against ProcessEvents. We assume, that if
845 // we are not in the Main-Thread ProcessEvents() is
846 // called by the TApplication Event Loop...
847 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/)
848 gClient->ProcessEventsFor(fTab);
849
850 *fLog << inf << "Adding Tab '" << name << "' (" << f->GetWidth() << "x";
851 *fLog << f->GetHeight() << ", TCanvas=" << &c << ")" << endl;
852
853 // return pointer to new canvas
854 return c;
855}
856
857// --------------------------------------------------------------------------
858//
859// Update a canvas in a tab, takes the corresponding TGCompositeFrame
860// as an argument. This is necessary, because not all functions
861// changing the contents of a canvas or pad can call SetModified()
862// for the corresponding tab. If this is not called correctly the
863// tab won't be updated calling TCanvas::Update(). So we simply
864// redraw it by our own (instead we could recursively call
865// TPad::Modified() for everything contained by the TCanvas and
866// call TCanvas::Update() afterwards)
867//
868void MStatusDisplay::UpdateTab(TGCompositeFrame *f)
869{
870 if (!f)
871 return;
872
873 TCanvas *c=GetCanvas(f);
874 if (!c)
875 return;
876
877 //
878 // If we are in a multithreaded environment (gThreadXAR) we
879 // have to make sure, that thus function is called from
880 // the main thread.
881 //
882 if (gThreadXAR)
883 {
884 // Tell the X-Requester how to call this method
885 TString str = Form("%d", (ULong_t)f);
886
887 TMethodCall call(IsA(), "UpdateTab", "NULL");
888 void *arr[4] = { NULL, &call, this, (void*)(const char*)str };
889
890 // If this is not the main thread return
891 if (((*gThreadXAR)("METH", 4, arr, NULL)))
892 return;
893 }
894
895 //
896 // Secure calls to update the tabs against itself, at least
897 // c->Paint() or c->Flush() may crash X (bad drawable).
898 // This makes sure, that a X call is not interuppted by
899 // another X-call which was started from an gui interrrupt
900 // in the same thread
901 //
902 if (fMutex->TryLock())
903 return;
904
905#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
906 TPad *padsav = (TPad*)gPad;
907 if (!gPad)
908 c->cd();
909#endif
910
911 if (!c->IsBatch())
912 c->FeedbackMode(kFALSE); // Goto double buffer mode
913
914 //
915 // Doing this ourself gives us the possibility to repaint
916 // the canvas in any case (Paint() instead of PaintModified())
917 //
918 c->Paint(); // Repaint all pads
919 c->Flush(); // Copy all pad pixmaps to the screen
920
921#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
922 if (padsav)
923 padsav->cd();
924 else
925 gPad=NULL;
926#endif
927
928 //c->SetCursor(kCross);
929
930 // Old version
931 //c->Modified();
932 //c->Update();
933 //c->Paint();
934
935 fMutex->UnLock();
936}
937
938// --------------------------------------------------------------------------
939//
940// Saves the given canvas (pad) or all pads (num<0) as a temporary
941// postscript file and prints it using 'lpr'. If a printer name is set
942// via SetPrinter 'lpr -Pname' is used.
943//
944Int_t MStatusDisplay::PrintToLpr(Int_t num)
945{
946 TString name = "mars";
947
948 for (int i=0; i<6; i++)
949 name += (char)(gRandom->Uniform(25)+65);
950
951 name += ".ps";
952
953 const Int_t pages = SaveAsPS(num, name);
954
955 SetStatusLine1("Printing...");
956 SetStatusLine2("");
957
958 if (!pages)
959 {
960 *fLog << warn << "MStatusDisplay::PrintToLpr: Sorry, couldn't save file as temporary postscript!" << endl;
961 SetStatusLine2("Failed!");
962 return 0;
963 }
964
965 TString cmd="lpr ";
966 if (!fPrinter.IsNull())
967 {
968 cmd += "-P";
969 cmd += fPrinter;
970 cmd += " ";
971 }
972 cmd += name;
973
974 gSystem->Exec(cmd);
975 gSystem->Unlink(name);
976
977 SetStatusLine2(Form("Done (%dpage(s))", pages));
978
979 return pages;
980}
981
982// --------------------------------------------------------------------------
983//
984// Remove tab no i if this tab contains a TRootEmbeddedCanvas
985//
986void MStatusDisplay::RemoveTab(int i)
987{
988 TGCompositeFrame *f = fTab->GetTabContainer(i);
989 if (!f)
990 return;
991
992 TRootEmbeddedCanvas *ec = GetEmbeddedCanvas(f);
993 if (!ec)
994 return;
995
996 TCanvas *c = ec->GetCanvas();
997 if (!c)
998 return;
999
1000 const TString name(c->GetName());
1001
1002 f->RemoveFrame(ec);
1003 delete fList->Remove(ec);
1004
1005 fTab->RemoveTab(i);
1006 fTab->SetTab(0);
1007
1008 // Looks strange...
1009 // const Int_t n = fTab->GetNumberOfTabs();
1010 // fTab->SetTab(i<=n-1 ? i : i-1);
1011
1012 // layout and map new tab
1013 Layout(); // seems to layout the TGCompositeFrame
1014 MapSubwindows(); // maps the TGCompositeFrame
1015 Layout(); // layout the embedded canvas in the frame
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 << inf << "Removed Tab #" << i << " '" << name << "'" << endl;
1026}
1027
1028// --------------------------------------------------------------------------
1029//
1030// Use this to check whether the MStatusDisplay still contains the
1031// TCanvas c. It could be removed meanwhile by menu usage.
1032//
1033Bool_t MStatusDisplay::HasCanvas(const TCanvas *c) const
1034{
1035 if (!c)
1036 return kFALSE;
1037
1038 if (gROOT->IsBatch())
1039 return (Bool_t)fBatch->FindObject(c);
1040
1041 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
1042 if (c==GetCanvas(i))
1043 return kTRUE;
1044 return kFALSE;
1045}
1046
1047/*
1048 if (...)
1049 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1050 else
1051 fMenu->RemovePopup("CaOs");
1052 fMenu->Resize(fMenu->GetDefaultSize());
1053 MapSubwindows();
1054 MapWindow();
1055 */
1056
1057void MStatusDisplay::Reset()
1058{
1059 for (int i=fTab->GetNumberOfTabs()-1; i>0; i--)
1060 RemoveTab(i);
1061}
1062
1063// --------------------------------------------------------------------------
1064//
1065// Process the kC_COMMAND, kCM_MENU messages
1066//
1067Bool_t MStatusDisplay::ProcessMessageCommandMenu(Long_t id)
1068{
1069 switch (id)
1070 {
1071 case kLoopStop:
1072 case kFileClose:
1073 case kFileExit:
1074 if (id==kFileExit || id==kFileClose)
1075 CloseWindow();
1076 fStatus = (Status_t)id;
1077 return kTRUE;
1078
1079 case kFileCanvas:
1080 new TCanvas;
1081 return kTRUE;
1082
1083 case kFileBrowser:
1084 new TBrowser;
1085 return kTRUE;
1086
1087 case kFileReset:
1088 Reset();
1089 return kTRUE;
1090
1091 case kFileOpen:
1092 Open();
1093 return kTRUE;
1094
1095 case kFileSaveAs:
1096 SaveAs();
1097 return kTRUE;
1098
1099 case kFileSaveAsPS:
1100 SaveAsPS();
1101 return kTRUE;
1102
1103 case kFileSaveAsGIF:
1104 SaveAsGIF();
1105 return kTRUE;
1106
1107 case kFileSaveAsC:
1108 SaveAsC();
1109 return kTRUE;
1110
1111 case kFileSaveAsRoot:
1112 SaveAsRoot();
1113 return kTRUE;
1114
1115 case kFilePrint:
1116 PrintToLpr();
1117 return kTRUE;
1118
1119 case kTabSaveAs:
1120 SaveAs(fTab->GetCurrent());
1121 return kTRUE;
1122
1123 case kTabSaveAsPS:
1124 SaveAsPS(fTab->GetCurrent());
1125 return kTRUE;
1126
1127 case kTabSaveAsGIF:
1128 SaveAsGIF(fTab->GetCurrent());
1129 return kTRUE;
1130
1131 case kTabSaveAsC:
1132 SaveAsC(fTab->GetCurrent());
1133 return kTRUE;
1134
1135 case kTabSaveAsRoot:
1136 SaveAsRoot(fTab->GetCurrent());
1137 return kTRUE;
1138
1139 case kTabPrint:
1140 PrintToLpr(fTab->GetCurrent());
1141 return kTRUE;
1142
1143 case kTabNext:
1144 fTab->SetTab(fTab->GetCurrent()+1);
1145 return kTRUE;
1146
1147 case kTabPrevious:
1148 fTab->SetTab(fTab->GetCurrent()-1);
1149 return kTRUE;
1150
1151 case kTabRemove:
1152 RemoveTab(fTab->GetCurrent());
1153 return kTRUE;
1154
1155 case kSize640:
1156 Resize(570, 480);
1157 return kTRUE;
1158 case kSize800:
1159 Resize(740, 600);
1160 return kTRUE;
1161 case kSize960:
1162 Resize(880, 700);
1163 return kTRUE;
1164 case kSize1024:
1165 Resize(980, 768);
1166 return kTRUE;
1167 case kSize1280:
1168 Resize(1280, 980);
1169 return kTRUE;
1170
1171 case kLogClear:
1172 fLogBox->Clear();
1173 return kTRUE;
1174 case kLogCopy:
1175 fLogBox->Copy();
1176 return kTRUE;
1177 case kLogSelect:
1178 fLogBox->SelectAll();
1179 return kTRUE;
1180 case kLogFind:
1181 new MSearch(this);
1182 return kTRUE;
1183 case kLogSave:
1184 SetStatusLine1("Saving log...");
1185 SetStatusLine2("");
1186 *fLog << inf << "Saving log... " << flush;
1187 if (fLogBox->GetText()->Save("statusdisplay.log"))
1188 {
1189 *fLog << "done." << endl;
1190 SetStatusLine2("done.");
1191 }
1192 else
1193 {
1194 *fLog << "failed!" << endl;
1195 SetStatusLine2("Failed!");
1196 }
1197 return kTRUE;
1198
1199 case kLogAppend:
1200 SetStatusLine1("Appending logg...");
1201 SetStatusLine2("");
1202 *fLog << inf << "Appending log... " << flush;
1203 if (fLogBox->GetText()->Append("statusdisplay.log"))
1204 {
1205 *fLog << "done." << endl;
1206 SetStatusLine2("done.");
1207 }
1208 else
1209 {
1210 *fLog << "failed!" << endl;
1211 SetStatusLine2("Failed!");
1212 }
1213 return kTRUE;
1214#ifdef DEBUG
1215 default:
1216 cout << "Command-Menu #" << id << endl;
1217#endif
1218 }
1219 return kTRUE;
1220
1221}
1222
1223// --------------------------------------------------------------------------
1224//
1225// Process the kC_COMMAND messages
1226//
1227Bool_t MStatusDisplay::ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2)
1228{
1229 switch (submsg)
1230 {
1231 case kCM_MENU: // 1
1232 return ProcessMessageCommandMenu(mp1); // mp2=userdata
1233 case kCM_TAB: // 8
1234 /*
1235 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
1236 fTab->GetTabContainer(i)->UnmapWindow();
1237 */
1238 UpdateTab(fTab->GetTabContainer(mp1));
1239 //fTab->GetTabContainer(mp1)->MapWindow();
1240
1241 /*
1242 if (mp1>0)
1243 fMenu->AddPopup("&CaOs", fCaOs, NULL);
1244 else
1245 fMenu->RemovePopup("CaOs");
1246 fMenu->Resize(fMenu->GetDefaultSize());
1247 MapSubwindows();
1248 MapWindow();
1249 */
1250 return kTRUE;
1251#ifdef DEBUG
1252 case kCM_MENUSELECT: // 2
1253 cout << "Command-Menuselect #" << mp1 << " (UserData=" << (void*)mp2 << ")" << endl;
1254 return kTRUE;
1255
1256 case kCM_BUTTON: // 3
1257 cout << "Command-Button." << endl;
1258 return kTRUE;
1259
1260 case kCM_CHECKBUTTON: // 4
1261 cout << "Command-CheckButton." << endl;
1262 return kTRUE;
1263
1264 case kCM_RADIOBUTTON: // 5
1265 cout << "Command-RadioButton." << endl;
1266 return kTRUE;
1267
1268 case kCM_LISTBOX: // 6
1269 cout << "Command-Listbox #" << mp1 << " (LineId #" << mp2 << ")" << endl;
1270 return kTRUE;
1271
1272 case kCM_COMBOBOX: // 7
1273 cout << "Command-ComboBox." << endl;
1274 return kTRUE;
1275 default:
1276 cout << "Command: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1277#endif
1278 }
1279 return kTRUE;
1280}
1281
1282// --------------------------------------------------------------------------
1283//
1284// Process the kC_TEXTVIEW messages
1285//
1286Bool_t MStatusDisplay::ProcessMessageTextview(Long_t submsg, Long_t mp1, Long_t mp2)
1287{
1288 // kC_TEXTVIEW, kTXT_ISMARKED, widget id, [true|false] //
1289 // kC_TEXTVIEW, kTXT_DATACHANGE, widget id, 0 //
1290 // kC_TEXTVIEW, kTXT_CLICK2, widget id, position (y << 16) | x) //
1291 // kC_TEXTVIEW, kTXT_CLICK3, widget id, position (y << 16) | x) //
1292 // kC_TEXTVIEW, kTXT_F3, widget id, true //
1293 // kC_TEXTVIEW, kTXT_OPEN, widget id, 0 //
1294 // kC_TEXTVIEW, kTXT_CLOSE, widget id, 0 //
1295 // kC_TEXTVIEW, kTXT_SAVE, widget id, 0 //
1296#ifdef DEBUG
1297 switch (submsg)
1298 {
1299 case kTXT_ISMARKED:
1300 cout << "Textview-IsMarked #" << mp1 << " " << (mp2?"yes":"no") << endl;
1301 return kTRUE;
1302
1303 case kTXT_DATACHANGE:
1304 cout << "Textview-DataChange #" << mp1 << endl;
1305 return kTRUE;
1306
1307 case kTXT_CLICK2:
1308 cout << "Textview-Click2 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
1309 return kTRUE;
1310
1311 case kTXT_CLICK3:
1312 cout << "Textview-Click3 #" << mp1 << " x=" << (mp2&0xffff) << " y= " << (mp2>>16) << endl;
1313 return kTRUE;
1314
1315 case kTXT_F3:
1316 cout << "Textview-F3 #" << mp1 << endl;
1317 return kTRUE;
1318
1319 case kTXT_OPEN:
1320 cout << "Textview-Open #" << mp1 << endl;
1321 return kTRUE;
1322
1323 case kTXT_CLOSE:
1324 cout << "Textview-Close #" << mp1 << endl;
1325 return kTRUE;
1326
1327 case kTXT_SAVE:
1328 cout << "Textview-Save #" << mp1 << endl;
1329 return kTRUE;
1330
1331 default:
1332 cout << "Textview: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1333 }
1334#endif
1335 return kTRUE;
1336}
1337
1338// --------------------------------------------------------------------------
1339//
1340// Process the kC_USER messages
1341//
1342Bool_t MStatusDisplay::ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2)
1343{
1344 // kS_START, case sensitive | backward<<1, char *txt
1345 switch (submsg)
1346 {
1347 case kS_START:
1348 fLogBox->Search((char*)mp2, !(mp1&2>>1), mp1&1);
1349 return kTRUE;
1350#ifdef DEBUG
1351 default:
1352 cout << "User: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1353#endif
1354 }
1355 return kTRUE;
1356}
1357
1358// --------------------------------------------------------------------------
1359//
1360// Process the messages from the GUI
1361//
1362Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
1363{
1364 // Can be found in WidgetMessageTypes.h
1365#ifdef DEBUG
1366 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
1367 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1368#endif
1369 switch (GET_MSG(msg))
1370 {
1371 case kC_COMMAND: // 1
1372 return ProcessMessageCommand(GET_SUBMSG(msg), mp1, mp2);
1373
1374 case kC_TEXTVIEW: // 9
1375 return ProcessMessageTextview(GET_SUBMSG(msg), mp1, mp2);
1376
1377 case kC_USER: // 1001
1378 return ProcessMessageUser(GET_SUBMSG(msg), mp1, mp2);
1379 }
1380#ifdef DEBUG
1381 cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
1382 cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
1383#endif
1384 return kTRUE;
1385}
1386
1387void MStatusDisplay::CloseWindow()
1388{
1389 // Got close message for this MainFrame. Calls parent CloseWindow()
1390 // (which destroys the window) and terminate the application.
1391 // The close message is generated by the window manager when its close
1392 // window menu item is selected.
1393
1394 // CloseWindow must be overwritten because otherwise CloseWindow
1395 // and the destructor are calling DestroyWindow which seems to be
1396 // in conflict with the TRootEmbeddedCanvas.
1397
1398 // FIXME: Make sure that the Status Display is deleted from every
1399 // where (eg Eventloop) first!
1400
1401 gLog << dbg << fName << " is on heap: " << (int)IsOnHeap() << endl;
1402
1403 if (TestBit(kExitLoopOnExit) || TestBit(kExitLoopOnClose))
1404 {
1405 gLog << dbg << "CloseWindow() calling ExitLoop." << endl;
1406 gSystem->ExitLoop();
1407 }
1408
1409 if (fIsLocked<=0 && IsOnHeap())
1410 {
1411 gLog << dbg << "delete " << fName << ";" << endl;
1412 delete this;
1413 }
1414 fStatus = kFileExit;
1415 gLog << dbg << fName << ".fStatus=kFileExit;" << endl;
1416}
1417
1418// --------------------------------------------------------------------------
1419//
1420// Calls SetBit(kNoContextMenu) for all TCanvas objects found in the
1421// Tabs.
1422//
1423void MStatusDisplay::SetNoContextMenu(Bool_t flag)
1424{
1425 if (fIsLocked>1 || gROOT->IsBatch())
1426 return;
1427
1428 flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
1429
1430 for (int i=1; i<fTab->GetNumberOfTabs(); i++)
1431 {
1432 TCanvas *c = GetCanvas(i);
1433 if (c)
1434 flag ? c->SetBit(kNoContextMenu) : c->ResetBit(kNoContextMenu);
1435 }
1436}
1437
1438// --------------------------------------------------------------------------
1439//
1440// Updates the canvas (if existing) in the currenly displayed Tab.
1441// The update intervall is controlled by StartUpdate and StopUpdate
1442//
1443Bool_t MStatusDisplay::HandleTimer(TTimer *timer)
1444{
1445 if (gROOT->IsBatch())
1446 return kTRUE;
1447
1448 const Int_t c = fTab->GetCurrent();
1449
1450 // Skip Legend Tab
1451 if (c==0)
1452 return kTRUE;
1453
1454 // Update a canvas tab (if visible)
1455 if (timer==&fTimer && c!=fLogIdx)
1456 {
1457 UpdateTab(fTab->GetCurrentContainer());
1458 return kTRUE;
1459 }
1460
1461 // update the logbook tab (if visible)
1462 if (timer==&fLogTimer && c==fLogIdx)
1463 {
1464 fLog->UpdateGui();
1465
1466 /*
1467 if (!fLogBox->TestBit(kHasChanged))
1468 return kTRUE;
1469
1470 fLogBox->ResetBit(kHasChanged);
1471 */
1472 return kTRUE;
1473 }
1474
1475 return kTRUE;
1476}
1477
1478// --------------------------------------------------------------------------
1479//
1480// Draws a clone of a canvas into a new canvas. Taken from TCanvas.
1481//
1482void MStatusDisplay::DrawClonePad(TCanvas &newc, const TCanvas &oldc) const
1483{
1484 //copy pad attributes
1485 newc.Range(oldc.GetX1(),oldc.GetY1(),oldc.GetX2(),oldc.GetY2());
1486 newc.SetTickx(oldc.GetTickx());
1487 newc.SetTicky(oldc.GetTicky());
1488 newc.SetGridx(oldc.GetGridx());
1489 newc.SetGridy(oldc.GetGridy());
1490 newc.SetLogx(oldc.GetLogx());
1491 newc.SetLogy(oldc.GetLogy());
1492 newc.SetLogz(oldc.GetLogz());
1493 newc.SetBorderSize(oldc.GetBorderSize());
1494 newc.SetBorderMode(oldc.GetBorderMode());
1495 ((TAttLine&)oldc).Copy((TAttLine&)newc);
1496 ((TAttFill&)oldc).Copy((TAttFill&)newc);
1497 ((TAttPad&)oldc).Copy((TAttPad&)newc);
1498
1499 //copy primitives
1500 TObject *obj;
1501 TIter next(oldc.GetListOfPrimitives());
1502 while ((obj=next())) {
1503 gROOT->SetSelectedPad(&newc);
1504 newc.GetListOfPrimitives()->Add(obj->Clone(),obj->GetDrawOption());
1505 }
1506 newc.Modified();
1507 newc.Update();
1508}
1509
1510// --------------------------------------------------------------------------
1511//
1512// Reads the contents of a saved MStatusDisplay from a file.
1513//
1514Int_t MStatusDisplay::Read(const char *name)
1515{
1516 if (!gFile)
1517 {
1518 *fLog << warn << "MStatusDisplay::Read: No file found. Please create a TFile first." << endl;
1519 return 0;
1520 }
1521
1522 if (!gFile->IsOpen())
1523 {
1524 *fLog << warn << "MStatusDisplay::Read: File not open. Please open the TFile first." << endl;
1525 return 0;
1526 }
1527
1528 TObjArray list;
1529
1530 const Int_t n = list.Read(name);
1531 if (n==0)
1532 {
1533 *fLog << warn << "MStatusDisplay::Read: No objects read." << endl;
1534 return 0;
1535 }
1536
1537 TIter Next(&list);
1538
1539 TObject *o=Next();
1540 if (!o)
1541 {
1542 *fLog << err << "MStatusDisplay: First entry missing in " << name << "." << endl;
1543 return 0;
1544 }
1545
1546 fTitle = o->GetTitle();
1547
1548 TCanvas *c;
1549 while ((c=(TCanvas*)Next()))
1550 if (!GetCanvas(c->GetName()))
1551 DrawClonePad(AddTab(c->GetName()), *c);
1552
1553 *fLog << inf << "MStatusDisplay: Key " << name << " with " << n << " keys read from file." << endl;
1554
1555 return n;
1556}
1557
1558// --------------------------------------------------------------------------
1559//
1560// Writes the contents of a MStatusDisplay to a file.
1561//
1562Int_t MStatusDisplay::Write(Int_t num, const char *name, Int_t option, Int_t bufsize)
1563{
1564 if (!gFile)
1565 {
1566 *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
1567 return 0;
1568 }
1569
1570 if (!gFile->IsOpen())
1571 {
1572 *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
1573 return 0;
1574 }
1575
1576 if (!gFile->IsWritable())
1577 {
1578 *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
1579 return 0;
1580 }
1581
1582 if (num==0)
1583 {
1584 *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
1585 return 0;
1586 }
1587
1588 if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
1589 {
1590 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
1591 return 0;
1592 }
1593 if (gROOT->IsBatch() && num>fBatch->GetSize())
1594 {
1595 *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
1596 return 0;
1597 }
1598
1599 TObjArray list;
1600
1601 TNamed named;
1602 named.SetTitle(fTitle);
1603 list.Add(&named);
1604
1605 const Int_t max = gROOT->IsBatch() ? fBatch->GetSize()+1 : fTab->GetNumberOfTabs();
1606 const Int_t from = num<0 ? 1 : num;
1607 const Int_t to = num<0 ? max : num+1;
1608
1609 TCanvas *c;
1610 for (int i=from; i<to; i++)
1611 if ((c = GetCanvas(i)))
1612 list.Add(c);
1613
1614 const Int_t n = list.Write(name, kSingleKey);
1615
1616 *fLog << inf << "MStatusDisplay: " << n << " keys written to file as key " << name << "." << endl;
1617
1618 return n;
1619}
1620
1621// --------------------------------------------------------------------------
1622//
1623// Use this to start the synchronous (GUI eventloop driven) tab update.
1624// Can also be used to change the update intervall. If millisec<0
1625// the intervall given in SetUpdateTime is used. If the intervall in
1626// SetUpdateTime is <0 nothing is done. (Call SetUpdateTime(-1) to
1627// disable the automatic update in a MEventloop.
1628//
1629void MStatusDisplay::StartUpdate(Int_t millisec)
1630{
1631 if (fIsLocked>1)
1632 return;
1633
1634 if (fTimer.GetTime()<TTime(0))
1635 return;
1636 fTimer.Start(millisec);
1637}
1638
1639// --------------------------------------------------------------------------
1640//
1641// Stops the automatic GUI update
1642//
1643void MStatusDisplay::StopUpdate()
1644{
1645 if (fIsLocked>1)
1646 return;
1647
1648 fTimer.Stop();
1649}
1650
1651// --------------------------------------------------------------------------
1652//
1653// Set the update interval for the GUI update, see StartUpdate.
1654//
1655void MStatusDisplay::SetUpdateTime(Long_t t)
1656{
1657 fTimer.SetTime(t);
1658}
1659
1660// --------------------------------------------------------------------------
1661//
1662// Set the background color in a canvas
1663//
1664void MStatusDisplay::CanvasSetFillColor(TPad &p, Int_t col) const
1665{
1666 TObject *obj;
1667
1668 // See also TPad::UseCurrentStyle
1669 TIter Next(p.GetListOfPrimitives());
1670 while ((obj=Next()))
1671 {
1672 if (obj->InheritsFrom(TPad::Class()))
1673 CanvasSetFillColor(*(TPad*)obj, col);
1674 if (obj->InheritsFrom(TFrame::Class()))
1675 ((TFrame*)obj)->SetFillColor(col);
1676 }
1677
1678 p.SetFillColor(col);
1679}
1680
1681void MStatusDisplay::AddExtension(TString &name, const TString &ext, Int_t num) const
1682{
1683 if (name.IsNull())
1684 {
1685 name = "status";
1686 if (num>0)
1687 {
1688 name += "-";
1689 name += num;
1690 }
1691 }
1692
1693 if (name.EndsWith("."+ext))
1694 return;
1695
1696 name += ".";
1697 name += ext;
1698}
1699
1700Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
1701{
1702 if (gROOT->IsBatch())
1703 return num>0 && num<=fBatch->GetSize() || num<0;
1704
1705 if (num>=fTab->GetNumberOfTabs())
1706 {
1707 *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
1708 return kFALSE;
1709 }
1710 if (num==0)
1711 {
1712 *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
1713 return kFALSE;
1714 }
1715 if (fTab->GetNumberOfTabs()<2 || !gPad)
1716 {
1717 *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
1718 return kFALSE;
1719 }
1720 return kTRUE;
1721}
1722
1723// --------------------------------------------------------------------------
1724//
1725// Insert the following two lines into the postscript header:
1726//
1727// %%DocumentPaperSizes: a4
1728// %%Orientation: Landscape
1729//
1730void MStatusDisplay::UpdatePSHeader(const TString &name) const
1731{
1732 const TString newstr("%%DocumentPaperSizes: a4\n%%Orientation: Landscape\n");
1733
1734 ifstream fin(name);
1735 ofstream fout(name+".$$$");
1736
1737 char c;
1738
1739 TString str;
1740 fin >> str >> c; // Read "%!PS-Adobe-2.0\n"
1741 fout << str << endl << newstr;
1742
1743 // Doing it in blocks seems not to gain much for small (MB) files
1744 while (fin)
1745 {
1746 fin.read(&c, 1);
1747 fout.write(&c, 1);
1748 }
1749
1750 gSystem->Unlink(name);
1751 gSystem->Rename(name+".$$$", name);
1752/*
1753 //
1754 // Old style algorithm. Shifts blocks inside a single file --- SLOW!
1755 //
1756 const Int_t l = newstr.Length();
1757
1758 Long_t t[4]; // { id, size, flags, modtime }
1759 gSystem->GetPathInfo(name, t, t+1, t+2, t+3);
1760
1761 char *c[2] = { new char[l], new char[l] };
1762
1763 fstream f(name, ios::in|ios::out);
1764
1765 TString str;
1766 f >> str >> c[0][0]; // Read "%!PS-Adobe-2.0\n" (Mini Header)
1767 f.read(c[0], l);
1768 f.seekp(-l, ios::cur);
1769 f.write(newstr, l);
1770
1771 int i=0;
1772 while (1)
1773 {
1774 f.read(c[(i+1)%2], l);
1775 f.seekp(-l, ios::cur);
1776
1777 if (f)
1778 {
1779 f.write(c[i%2],l);
1780 i++;
1781 i%=2;
1782 continue;
1783 }
1784
1785 const Int_t ssz = str.Length()+1; // Length of Mini-Header
1786 const Int_t block = t[1]-ssz; // Length of block to be shifted
1787 const Int_t size = block%l; // Reminder
1788 const Int_t pos = (block/l)*l + ssz + 1; // Position to start writing
1789
1790 f.clear();
1791 f.seekp(pos);
1792 f.write(c[i%2], l);
1793 f.write(c[(i+1)%2], size);
1794 break;
1795 }
1796
1797 delete c[1];
1798 delete c[0];
1799*/
1800}
1801
1802// --------------------------------------------------------------------------
1803//
1804// In case of num<0 all tabs are written into the PS file. If num>0
1805// the canvas in the corresponding tab is written to the file.
1806// Name is the name of the file (with or without extension).
1807//
1808// Returns the number of pages written.
1809//
1810// To write all tabs you can also use SaveAsPS(name)
1811//
1812// If the third argument is given a bottom line is drawn with the text
1813// under it. If no argument is given a bottom line is drawn if
1814// fTitle (SetTitle) is not empty.
1815//
1816Int_t MStatusDisplay::SaveAsPS(Int_t num, TString name, const TString addon)
1817{
1818 SetStatusLine1("Writing Postscript file...");
1819 SetStatusLine2("");
1820
1821 if (!CheckTabForCanvas(num))
1822 {
1823 SetStatusLine2("Failed!");
1824 return 0;
1825 }
1826
1827 AddExtension(name, "ps", num);
1828
1829 if (num<0)
1830 *fLog << inf << "Open ps-File: " << name << endl;
1831
1832 TPad *padsav = (TPad*)gPad;
1833 TVirtualPS *psave = gVirtualPS;
1834
1835 TDatime d;
1836
1837 TPostScript ps(name, 112);
1838 ps.SetBit(TPad::kPrintingPS);
1839 ps.PrintFast(13, "/nan {1} def ");
1840
1841 gVirtualPS = &ps;
1842
1843 //
1844 // Create a list to delete the canvas clones
1845 //
1846 TList l;
1847 l.SetOwner();
1848
1849 //
1850 // Create some GUI elements for a page legend
1851 //
1852 TLine line;
1853
1854 int page = 1;
1855
1856 //
1857 // Maintain tab numbers
1858 //
1859 const Int_t max = gROOT->IsBatch() ? fBatch->GetSize()+1 : fTab->GetNumberOfTabs();
1860 const Int_t from = num<0 ? 1 : num;
1861 const Int_t to = num<0 ? max : num+1;
1862
1863 for (int i=from; i<to; i++)
1864 {
1865 TCanvas *c;
1866 if (!(c = GetCanvas(i)))
1867 {
1868 if (num<0)
1869 *fLog << inf << " - ";
1870 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
1871 continue;
1872 }
1873
1874 SetStatusLine2(Form("Tab #%d", i));
1875
1876 //
1877 // Init page and page size, make sure, that the canvas in the file
1878 // has the same Aspect Ratio than on the screen.
1879 //
1880 ps.NewPage();
1881
1882 //
1883 // 28 is used here to scale the canvas into a height of 28,
1884 // such that the page title can be set above the canvas...
1885 //
1886 Float_t psw = 28.0; // A4 - width (29.7)
1887 Float_t psh = 21.0; // A4 - height (21.0)
1888
1889 const Float_t cw = c->GetWw();
1890 const Float_t ch = c->GetWh();
1891
1892 if (psw/psh>cw/ch)
1893 psw = cw/ch*psh;
1894 else
1895 psh = ch/cw*psw;
1896
1897 ps.Range(psw, psh); // A4
1898
1899 //
1900 // Clone canvas and change background color and schedule for
1901 // deletion
1902 //
1903 TCanvas *n = (TCanvas*)c->Clone();
1904 CanvasSetFillColor(*n, kWhite);
1905 l.Add(n);
1906
1907 //
1908 // Paint canvas into root file
1909 //
1910 if (num<0)
1911 *fLog << inf << " - ";
1912 *fLog << inf << "Writing Tab #" << i << ": " << c->GetName() << " (" << c << ") ";
1913 if (num>0)
1914 *fLog << "to " << name;
1915 *fLog << "... " << flush;
1916
1917 n->SetBatch(kTRUE);
1918 n->Paint();
1919
1920 //
1921 // Use the canvas as coordinate system for the overlaying text
1922 //
1923 gPad = n;
1924
1925 //
1926 // Print overlaying text (NDC = %)
1927 //
1928 ps.SetTextColor(kBlack);
1929 ps.SetTextSize(0.015);
1930 ps.SetTextFont(22);
1931 ps.SetTextAlign(11); // left top
1932 ps.TextNDC(0, 1.015, TString(" ")+n->GetName());
1933 ps.SetTextAlign(21); // cent top
1934 ps.TextNDC(0.5, 1.015, TString("MARS - Magic Analysis and Reconstruction Software - ")+d.AsString());
1935 ps.SetTextAlign(31); // right top
1936 ps.TextNDC(1, 1.015, Form("Page No.%i (%i) ", page++, i));
1937 line.PaintLineNDC(0, 1.01, 1, 1.01);
1938
1939 TString txt(addon.IsNull() ? fTitle : addon);
1940 if (!txt.IsNull())
1941 {
1942 line.PaintLineNDC(0, -0.00, 1, -0.00);
1943 ps.SetTextAlign(23); // cent bottom
1944 ps.TextNDC(0.5, -0.005, txt);
1945 }
1946
1947 //
1948 // Finish drawing page
1949 //
1950 n->SetBatch(kFALSE);
1951 if (num<0)
1952 *fLog << "done." << endl;
1953 }
1954
1955 gPad = NULL; // Important!
1956 l.Delete();
1957
1958 ps.Close();
1959
1960 SetStatusLine2("Updating header of PS file...");
1961
1962 *fLog << inf << " - Updating header of PS file... " << flush;
1963 UpdatePSHeader(name);
1964 *fLog << inf << "done." << endl;
1965
1966 gVirtualPS = psave;
1967 if (padsav)
1968 padsav->cd();
1969
1970 *fLog << inf << "done." << endl;
1971
1972 SetStatusLine2(Form("Done (%dpages)", page-1));
1973
1974 return page-1;
1975}
1976
1977Bool_t MStatusDisplay::SaveAsGIF(Int_t num, TString name)
1978{
1979 if (gROOT->IsBatch())
1980 {
1981 *fLog << warn << "Sorry, writing gif-files is not available in batch mode." << endl;
1982 return 0;
1983 }
1984 SetStatusLine1("Writing GIF file...");
1985 SetStatusLine2("");
1986
1987 if (!CheckTabForCanvas(num))
1988 {
1989 SetStatusLine2("Failed!");
1990 return 0;
1991 }
1992
1993 AddExtension(name, "gif", num);
1994
1995 if (num<0)
1996 *fLog << inf << "Writing gif-Files..." << endl;
1997
1998 TPad *padsav = (TPad*)gPad;
1999
2000 int page = 1;
2001
2002 //
2003 // Maintain tab numbers
2004 //
2005 const Int_t from = num<0 ? 1 : num;
2006 const Int_t to = num<0 ? fTab->GetNumberOfTabs() : num+1;
2007
2008 for (int i=from; i<to; i++)
2009 {
2010 TCanvas *c;
2011 if (!(c = GetCanvas(i)))
2012 {
2013 if (num<0)
2014 *fLog << inf << " - ";
2015 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
2016 continue;
2017 }
2018
2019 SetStatusLine2(Form("Tab #%d", i));
2020
2021 //
2022 // Clone canvas and change background color and schedule for
2023 // deletion
2024 //
2025 //TCanvas *n = (TCanvas*)c->Clone();
2026 //CanvasSetFillColor(*n, kWhite);
2027
2028 //
2029 // Paint canvas into root file
2030 //
2031 TString writename = name;
2032 if (num<0)
2033 {
2034 TString numname = "-";
2035 numname += i;
2036 writename.Insert(name.Last('.'), numname);
2037 }
2038 if (num<0)
2039 *fLog << inf << " - ";
2040 *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << c << ") ";
2041 if (num>0)
2042 *fLog << "to " << name;
2043 *fLog << "..." << flush;
2044
2045 c->Draw();
2046 c->SaveAs(writename);
2047 /*
2048 n->Draw();
2049 n->SaveAs(writename);
2050 delete n;
2051 */
2052
2053 if (num<0)
2054 *fLog << "done." << endl;
2055 }
2056
2057 padsav->cd();
2058
2059 *fLog << inf << "done." << endl;
2060
2061 SetStatusLine2("Done.");
2062
2063 return page-1;
2064}
2065
2066Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
2067{
2068 SetStatusLine1("Writing C++ file...");
2069 SetStatusLine2("");
2070
2071 if (!CheckTabForCanvas(num))
2072 {
2073 SetStatusLine2("Failed!");
2074 return 0;
2075 }
2076
2077 AddExtension(name, "C", num);
2078
2079 if (num<0)
2080 *fLog << inf << "Writing C-Files..." << endl;
2081
2082 TPad *padsav = (TPad*)gPad;
2083
2084 int page = 1;
2085
2086 //
2087 // Maintain tab numbers
2088 //
2089 const Int_t from = num<0 ? 1 : num;
2090 const Int_t to = num<0 ? fTab->GetNumberOfTabs() : num+1;
2091
2092 for (int i=from; i<to; i++)
2093 {
2094 TCanvas *c;
2095 if (!(c = GetCanvas(i)))
2096 {
2097 if (num<0)
2098 *fLog << inf << " - ";
2099 *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
2100 continue;
2101 }
2102
2103 SetStatusLine2(Form("Tab #%d", i));
2104
2105 //
2106 // Clone canvas and change background color and schedule for
2107 // deletion
2108 //
2109 TCanvas *n = (TCanvas*)c->Clone();
2110 CanvasSetFillColor(*n, kWhite);
2111
2112 //
2113 // Paint canvas into root file
2114 //
2115 TString writename = name;
2116 if (num<0)
2117 {
2118 TString numname = "-";
2119 numname += i;
2120 writename.Insert(name.Last('.'), numname);
2121 }
2122 if (num<0)
2123 *fLog << inf << " - ";
2124 *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << n << ") ";
2125 if (num>0)
2126 *fLog << "to " << name;
2127 *fLog << "..." << flush;
2128
2129 n->SaveSource(writename, "");
2130 delete n;
2131
2132 if (num<0)
2133 *fLog << "done." << endl;
2134 }
2135
2136 padsav->cd();
2137
2138 *fLog << inf << "done." << endl;
2139
2140 SetStatusLine2("Done.");
2141
2142 return page-1;
2143}
2144
2145// --------------------------------------------------------------------------
2146//
2147// In case of num<0 all tabs are written into the PS file. If num>0
2148// the canvas in the corresponding tab is written to the file.
2149// Name is the name of the file (with or without extension).
2150//
2151// Returns the number of keys written.
2152//
2153// To write all tabs you can also use SaveAsPS(name)
2154//
2155Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name)
2156{
2157 SetStatusLine1("Writing root file...");
2158 SetStatusLine2("");
2159
2160 if (!CheckTabForCanvas(num))
2161 {
2162 SetStatusLine2("Failed!");
2163 return 0;
2164 }
2165
2166 AddExtension(name, "root", num);
2167
2168 TFile *fsave = gFile;
2169 TFile file(name, "RECREATE", "MARS - Status Window Contents", 9);
2170 const Int_t keys = Write(num);
2171 gFile = fsave;
2172
2173 SetStatusLine2("Done.");
2174
2175 return keys;
2176}
2177
2178// --------------------------------------------------------------------------
2179//
2180// Opens a save as dialog
2181//
2182Int_t MStatusDisplay::SaveAs(Int_t num)
2183{
2184 static const char *gSaveAsTypes[] =
2185 {
2186 "PostScript", "*.ps",
2187 "Gif files", "*.gif",
2188 "Macro files", "*.C",
2189 "ROOT files", "*.root",
2190 "All files", "*",
2191 NULL, NULL
2192 };
2193
2194 static TString dir(".");
2195
2196 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
2197
2198 fi.fFileTypes = (const char**)gSaveAsTypes;
2199 fi.fIniDir = StrDup(dir);
2200
2201 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
2202
2203 if (!fi.fFilename)
2204 return 0;
2205
2206 dir = fi.fIniDir;
2207
2208 const TString name(fi.fFilename);
2209
2210 if (name.EndsWith(".root")) return SaveAsRoot(num, name);
2211 if (name.EndsWith(".ps")) return SaveAsPS(num, name);
2212 if (name.EndsWith(".gif")) return SaveAsGIF(num, name);
2213 if (name.EndsWith(".C")) return SaveAsC(num, name);
2214
2215 Warning("MStatusDisplay::SaveAs", "Unknown Extension: %s", fi.fFilename);
2216 return 0;
2217}
2218
2219// --------------------------------------------------------------------------
2220//
2221// Open contents of a MStatusDisplay with key name from file fname.
2222//
2223Int_t MStatusDisplay::Open(TString fname, const char *name)
2224{
2225 TFile file(fname, "READ");
2226 if (file.IsZombie())
2227 {
2228 gLog << warn << "WARNING - Cannot open file " << fname << endl;
2229 return 0;
2230 }
2231
2232 return Read(name);
2233}
2234
2235// --------------------------------------------------------------------------
2236//
2237// Opens an open dialog
2238//
2239Int_t MStatusDisplay::Open()
2240{
2241 static const char *gOpenTypes[] =
2242 {
2243 "ROOT files", "*.root",
2244 "All files", "*",
2245 NULL, NULL
2246 };
2247
2248 static TString dir(".");
2249
2250 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
2251
2252 fi.fFileTypes = (const char**)gOpenTypes;
2253 fi.fIniDir = StrDup(dir);
2254
2255 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
2256
2257 if (!fi.fFilename)
2258 return 0;
2259
2260 dir = fi.fIniDir;
2261
2262 return Open(fi.fFilename);
2263}
2264
2265Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
2266{
2267 //
2268 // The initialization of the GUI is not yet enough finished...
2269 //
2270 if (!fTab)
2271 return kTRUE;
2272
2273 UInt_t w = evt->fWidth;
2274 UInt_t h = evt->fHeight;
2275
2276 /*
2277 cout << "Old: " << GetWidth() << " " << GetHeight() << " " << GetBorderWidth() << endl;
2278 cout << "New: " << w << " " << h << " ";
2279 cout << "New: " << GetDefaultWidth() << " " << GetDefaultHeight() << " " << endl;
2280 */
2281
2282 Bool_t wchanged = w!=GetWidth();
2283 Bool_t hchanged = h!=GetHeight();
2284
2285 if (!wchanged && !hchanged)
2286 {
2287 Layout();
2288 // FIXME: Make sure that this doesn't result in endless loops.
2289 return kTRUE;
2290 }
2291
2292
2293 if (GetWidth()==1 && GetHeight()==1)
2294 return kTRUE;
2295
2296 // calculate the constant part of the window
2297 const UInt_t cw = GetWidth() -fTab->GetWidth();
2298 const UInt_t ch = GetHeight()-fTab->GetHeight();
2299
2300 // calculate new size of frame (canvas @ 1:sqrt(2))
2301 if (hchanged)
2302 w = (UInt_t)((h-ch)*sqrt(2.)+.5)+cw;
2303 else
2304 h = (UInt_t)((w-cw)/sqrt(2.)+.5)+ch;
2305
2306 // resize frame
2307 Resize(w, h);
2308
2309 return kTRUE;
2310}
2311
2312Bool_t MStatusDisplay::HandleEvent(Event_t *event)
2313{
2314 Bool_t rc = TGMainFrame::HandleEvent(event);
2315
2316 //
2317 // This fixes a bug in older root versions which makes
2318 // TCanvas crash if gPad==NULL. So we make sure, that
2319 // gPad!=NULL -- be carfull, this may have other side
2320 // effects.
2321 //
2322#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01)
2323 if (!gPad && fTab)
2324 for (int i=0; i<fTab->GetNumberOfTabs(); i++)
2325 {
2326 TCanvas *c = GetCanvas(i);
2327 if (c)
2328 {
2329 c->cd();
2330 gLog << dbg << "MStatusDisplay::HandleEvent - Workaround: gPad=" << gPad << "." << endl;
2331 break;
2332 }
2333 }
2334#endif
2335
2336 return rc;
2337}
Note: See TracBrowser for help on using the repository browser.