Index: trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2194)
+++ trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2207)
@@ -340,4 +340,7 @@
 void MStatusDisplay::SetLogStream(MLog *log, Bool_t enable)
 {
+    if (gROOT->IsBatch())
+        return;
+
     if (log && fLogBox==NULL)
     {
@@ -455,4 +458,6 @@
 void MStatusDisplay::SetStatusLine1(const char *txt)
 {
+    if (gROOT->IsBatch())
+        return;
     fStatusBar->SetText(txt, 0);
     gClient->ProcessEventsFor(fStatusBar);
@@ -465,4 +470,6 @@
 void MStatusDisplay::SetStatusLine2(const char *txt)
 {
+    if (gROOT->IsBatch())
+        return;
     fStatusBar->SetText(txt, 1);
     gClient->ProcessEventsFor(fStatusBar);
@@ -491,10 +498,11 @@
 //
 MStatusDisplay::MStatusDisplay(Long_t t)
-: TGMainFrame(gClient->GetRoot(), 1, 1), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLog(&gLog), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0)
+: 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)
 {
     gROOT->GetListOfSpecials()->Add(this);
-    gROOT->GetListOfCleanups()->Add(this);
 
     fFont = gVirtualX->LoadQueryFont("7x13bold");
+
+    fBatch.SetOwner();
 
     //
@@ -521,8 +529,11 @@
     // Add Widgets (from top to bottom)
     //
-    AddMenuBar();
-    AddTabs();
-    AddProgressBar();
-    AddStatusBar();
+    if (gClient) // BATCH MODE
+    {
+        AddMenuBar();
+        AddTabs();
+        AddProgressBar();
+        AddStatusBar();
+    }
 
     //
@@ -547,4 +558,6 @@
 MStatusDisplay::~MStatusDisplay()
 {
+    gROOT->GetListOfSpecials()->Remove(this);
+
     SetLogStream(NULL);
 
@@ -553,8 +566,5 @@
     if (fFont)
         gVirtualX->DeleteFont(fFont);
-
-    gROOT->GetListOfSpecials()->Remove(this);
-    gROOT->GetListOfCleanups()->Remove(this);
-} 
+}
 
 // --------------------------------------------------------------------------
@@ -594,4 +604,7 @@
 TCanvas *MStatusDisplay::GetCanvas(int i) const
 {
+    if (gROOT->IsBatch())
+        return (TCanvas*)fBatch.At(i-1);
+
     if (i<0 || i>=fTab->GetNumberOfTabs())
     {
@@ -656,8 +669,15 @@
 TCanvas &MStatusDisplay::AddTab(const char *name)
 {
+    if (gROOT->IsBatch())
+    {
+        TCanvas *c = new TCanvas(name, name);
+        fBatch.Add(c);
+        return *c;
+    }
+
     // Add new tab
     TGCompositeFrame *f = fTab->AddTab(name);
 
-    // create root embedded canvas and add it to the tab
+    // create root emb 0edded canvas and add it to the tab
     TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, f->GetWidth(), f->GetHeight(), 0);
     f->AddFrame(ec, fLayCanvas);
@@ -676,9 +696,10 @@
     // layout and map new tab
 //#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,00)
+//    MapSubwindows();
+//    Layout();
+//#else
+    Layout();
     MapSubwindows();
     Layout();
-//#else
-//    Layout();
-//    MapSubwindows();
 //#endif
 
@@ -707,7 +728,14 @@
         return;
 
-    c->Modified();
-    c->Update();
-    c->Paint();
+    // 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
+    //c->SetCursor(kCross);
+
+    // Old version
+    //c->Modified();
+    //c->Update();
+    //c->Paint();
 }
 
@@ -803,4 +831,7 @@
 Bool_t MStatusDisplay::HasCanvas(const TCanvas *c) const
 {
+    if (gROOT->IsBatch())
+        return fBatch.FindObject(c);
+
     for (int i=1; i<fTab->GetNumberOfTabs(); i++)
         if (c==GetCanvas(i))
@@ -829,5 +860,5 @@
     case kLoopStop:
     case kFileExit:
-        if (id==kFileExit && !fIsLocked)
+        if (id==kFileExit)
             delete this;
         fStatus = (Status_t)id;
@@ -1154,5 +1185,5 @@
 void MStatusDisplay::SetNoContextMenu(Bool_t flag)
 {
-    if (fIsLocked>1)
+    if (fIsLocked>1 || gROOT->IsBatch())
         return;
 
@@ -1173,4 +1204,7 @@
 Bool_t MStatusDisplay::HandleTimer(TTimer *timer)
 {
+    if (gROOT->IsBatch())
+        return kTRUE;
+
     const Int_t c = fTab->GetCurrent();
 
@@ -1302,14 +1336,20 @@
     }
 
-    if (num>=fTab->GetNumberOfTabs())
+    if (!gROOT->IsBatch() && num>=fTab->GetNumberOfTabs())
     {
         *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
         return 0;
     }
+    if (gROOT->IsBatch() && num>fBatch.GetSize())
+    {
+        *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
+        return 0;
+    }
 
     TObjArray list;
 
-    const Int_t from = num<0 ? 1 : num;
-    const Int_t to   = num<0 ? fTab->GetNumberOfTabs() : num+1;
+    const Int_t max  = gROOT->IsBatch() ? fBatch.GetSize()+1 : fTab->GetNumberOfTabs();
+    const Int_t from = num<0 ?   1 : num;
+    const Int_t to   = num<0 ? max : num+1;
 
     TCanvas *c;
@@ -1406,4 +1446,7 @@
 Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
 {
+    if (gROOT->IsBatch())
+        return num>0 && num<=fBatch.GetSize() || num<0;
+
     if (num>=fTab->GetNumberOfTabs())
     {
@@ -1530,6 +1573,7 @@
     // Maintain tab numbers
     //
-    const Int_t from = num<0 ? 1 : num;
-    const Int_t to   = num<0 ? fTab->GetNumberOfTabs() : num+1;
+    const Int_t max  = gROOT->IsBatch() ? fBatch.GetSize()+1 : fTab->GetNumberOfTabs();
+    const Int_t from = num<0 ?   1 : num;
+    const Int_t to   = num<0 ? max : num+1;
 
     for (int i=from; i<to; i++)
@@ -1572,5 +1616,4 @@
         CanvasSetFillColor(*n, kWhite);
         l.Add(n);
-
         //
         // Paint canvas into root file
@@ -1578,5 +1621,5 @@
         if (num<0)
             *fLog << inf << " - ";
-        *fLog << inf << "Writing Tab #" << i << ": " << c->GetName() << " (" << n << ") ";
+        *fLog << inf << "Writing Tab #" << i << ": " << c->GetName() << " (" << c << ") ";
         if (num>0)
             *fLog << "to " << name;
@@ -1614,5 +1657,4 @@
 
     gPad = NULL; // Important!
-
     l.Delete();
 
@@ -1621,5 +1663,6 @@
 
     gVirtualPS = psave;
-    padsav->cd();
+    if (padsav)
+        padsav->cd();
 
     *fLog << inf << "done." << endl;
@@ -1632,4 +1675,9 @@
 Bool_t MStatusDisplay::SaveAsGIF(Int_t num, TString name)
 {
+    if (gROOT->IsBatch())
+    {
+        *fLog << warn << "Sorry, writing gif-files is not available in batch mode." << endl;
+        return 0;
+    }
     SetStatusLine1("Writing GIF file...");
     SetStatusLine2("");
