Index: trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2377)
+++ trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2386)
@@ -75,4 +75,5 @@
 #include <TObjArray.h>            // TObjArray
 #include <TPostScript.h>          // TPostScript
+#include <TInterpreter.h>         // gInterpreter
 
 #include <TGTab.h>                // TGTab
@@ -186,4 +187,5 @@
     //filemenu->AddEntry("Set printer &name",    kFilePrinterName);
     filemenu->AddSeparator();
+    filemenu->AddEntry("C&lose", kFileClose);
     filemenu->AddEntry("E&xit", kFileExit);
     filemenu->Associate(this);
@@ -507,8 +509,17 @@
 : TGMainFrame(gClient ? gClient->GetRoot() : NULL, 1, 1), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLog(&gLog), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0)
 {
+    //
+    // This is a possibility for the user to check whether this
+    // object has already been deleted. It will be removed
+    // from the list in the destructor.
+    //
     gROOT->GetListOfSpecials()->Add(this);
 
     fFont = gVirtualX->LoadQueryFont("7x13bold");
 
+    //
+    // In case we are in batch mode use a list of canvases
+    // instead of the Root Embedded Canvases in the TGTab
+    //
     fBatch = new TList;
     fBatch->SetOwner();
@@ -566,11 +577,33 @@
 MStatusDisplay::~MStatusDisplay()
 {
+    //
+    // Delete object from global object table so it cannot
+    // be deleted by chance a second time
+    //
+    gInterpreter->DeleteGlobal(this);
+
+    //
+    // This is a possibility for the user to check whether this
+    // object has already been deleted. It has been added
+    // to the list in the constructor.
+    //
     gROOT->GetListOfSpecials()->Remove(this);
 
     SetLogStream(NULL);
 
+    //
+    // Delete the list of objects corresponding to this object
+    //
     delete fList;
+
+    //
+    // Delete the list list of canvases used in batch mode
+    // instead of the Root Embedded Canvases in the TGTab
+    //
     delete fBatch;
 
+    //
+    // Delete the font used for the logging window
+    //
     if (fFont)
         gVirtualX->DeleteFont(fFont);
@@ -671,4 +704,41 @@
 }
 
+/*
+class MCanvas : public TRootEmbeddedCanvas
+{
+public:
+    MCanvas(const char* name, const TGWindow* p, UInt_t w, UInt_t h, UInt_t o) :
+              TRootEmbeddedCanvas(name, p, w, h, o) {}
+              void Layout()
+              {
+                  cout << "EmbLayout: " << GetCanvas()->GetName() << endl;
+
+                  // Create layout for canvas. Depending on the size of the container
+                  // we need to add the scrollbars.
+                  TRootEmbeddedCanvas::Layout();
+              }
+};
+*/
+
+TGCompositeFrame *MStatusDisplay::AddRawTab(const char *name)
+{
+    // Add new tab
+    TGCompositeFrame *f = fTab->AddTab(name);
+
+    // layout and map new tab
+    Layout();
+    MapSubwindows();
+    Layout();
+
+    // display new tab in the main frame
+    gClient->ProcessEventsFor(fTab);
+
+    *fLog << inf << "Adding Raw Tab '" << name << "' (" << f->GetWidth() << "x";
+    *fLog << f->GetHeight() << ")" << endl;
+
+    // return pointer to new canvas
+    return f;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -688,5 +758,5 @@
     TGCompositeFrame *f = fTab->AddTab(name);
 
-    // create root emb 0edded canvas and add it to the tab
+    // create root embedded canvas and add it to the tab
     TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, f->GetWidth(), f->GetHeight(), 0);
     f->AddFrame(ec, fLayCanvas);
@@ -723,4 +793,5 @@
 }
 
+
 // --------------------------------------------------------------------------
 //
@@ -737,8 +808,19 @@
         return;
 
-    // Code taken from TCanvas::Update() and TCanvas::Paint
-    c->FeedbackMode(kFALSE);  // Goto double buffer mode
-    c->Paint();               // Repaint all pad's
-    c->Flush();               // Copy all pad pixmaps to the screen
+    // Code taken from TCanvas::Update() and TCanvas::Paint()
+    // replaces PaintModified() by Paint()
+    if (gThreadXAR)
+    {
+        void *arr[2] = { NULL, c };
+        if (((*gThreadXAR)("CUPD", 2, arr, NULL)))
+            return;
+    }
+
+    if (!c->IsBatch())
+        c->FeedbackMode(kFALSE);  // Goto double buffer mode
+
+    c->Paint();                   // Repaint all pads
+    c->Flush();                   // Copy all pad pixmaps to the screen
+
     //c->SetCursor(kCross);
 
@@ -871,7 +953,8 @@
     {
     case kLoopStop:
+    case kFileClose:
     case kFileExit:
-        if (id==kFileExit)
-            delete this;
+        if (id==kFileExit || id==kFileClose)
+            CloseWindow();
         fStatus = (Status_t)id;
         return kTRUE;
@@ -1029,8 +1112,11 @@
         return ProcessMessageCommandMenu(mp1); // mp2=userdata
     case kCM_TAB:
-        for (int i=1; i<fTab->GetNumberOfTabs(); i++)
-            fTab->GetTabContainer(i)->UnmapWindow();
+        /*
+         for (int i=0; i<fTab->GetNumberOfTabs(); i++)
+         fTab->GetTabContainer(i)->UnmapWindow();
+         */
         UpdateTab(fTab->GetTabContainer(mp1));
-        fTab->GetTabContainer(mp1)->MapWindow();
+        //fTab->GetTabContainer(mp1)->MapWindow();
+
         /*
         if (mp1>0)
@@ -1187,5 +1273,13 @@
     // and the destructor are calling DestroyWindow which seems to be
     // in conflict with the TRootEmbeddedCanvas.
-    delete this;
+
+    // FIXME: Make sure that the Status Display is deleted from every
+    //        where (eg Eventloop) first!
+
+    gLog << dbg << "MStatusDisplay is on heap: " << (int)IsOnHeap() << endl;
+
+    if (fIsLocked<=0 && IsOnHeap())
+        delete this;
+    fStatus = kFileExit;
 }
 
@@ -1201,4 +1295,5 @@
 
     flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
+
     for (int i=1; i<fTab->GetNumberOfTabs(); i++)
     {
@@ -1563,4 +1658,6 @@
     TVirtualPS *psave  = gVirtualPS;
 
+    TDatime d;
+
     TPostScript ps(name, 112);
     ps.SetBit(TPad::kPrintingPS);
@@ -1608,6 +1705,10 @@
         ps.NewPage();
 
-        Float_t psw = 26; // A4 - width
-        Float_t psh = 20; // A4 - height
+        //
+        // 26 is used here to scale the canvas into a height of 26,
+        // such that the page title can be set above the canvas...
+        //
+        Float_t psw = 26; //29.7; // A4 - width
+        Float_t psh = 21.0; // A4 - height
 
         const Float_t cw = c->GetWw();
@@ -1655,5 +1756,5 @@
         ps.TextNDC(0, 1.02, TString("  ")+n->GetName());
         ps.SetTextAlign(21); // cent top
-        ps.TextNDC(0.5, 1.02, "MARS - Magic Analysis and Reconstruction Software");
+        ps.TextNDC(0.5, 1.02, TString("MARS - Magic Analysis and Reconstruction Software - ")+d.AsString());
         ps.SetTextAlign(31); // right top
         ps.TextNDC(1, 1.02, Form("Page No.%i (%i)  ", page++, i));
