Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 7826)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 7827)
@@ -339,4 +339,5 @@
     sizemenu->AddEntry("Fit to 1400x1050",  kSize1400);
     sizemenu->AddEntry("Fit to 1600x1200",  kSize1600);
+    sizemenu->AddEntry("Fit to &Desktop",   kSizeOptimum);
     sizemenu->Associate(this);
 
@@ -672,7 +673,12 @@
 //   always by deleting the corresponding object.
 //
+// You can give either width or height. (Set the value not given to -1)
+// The other value is calculated accordingly. If width and height are
+// given height is ignored. If width=height=0 an optimum size from
+// the desktop size is calculated.
+//
 // Update time default: 10s
 //
-MStatusDisplay::MStatusDisplay(Long_t t)
+MStatusDisplay::MStatusDisplay(Int_t w, Int_t h, Long_t t)
 : 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)
 {
@@ -714,5 +720,8 @@
     // In newer root versions gClient!=NULL in batch mode!
     if (!gClient || !gClient->GetRoot() || gROOT->IsBatch()) // BATCH MODE
+    {
+        Resize(644, 484);
         return;
+    }
 
     AddMenuBar();
@@ -725,6 +734,12 @@
     // set the smallest and biggest size of the Main frame
     // and move it to its appearance position
-    SetWMSizeHints(572, 480, 2048, 1536, 1, 1);
-    MoveResize(rand()%100+572, rand()%100+480, 572, 480);
+    SetWMSizeHints(566, 476, 2048, 1536, 1, 1);
+    MoveResize(rand()%100+566, rand()%100+476, 566, 476);
+    if (h>0)
+        SetDisplayHeight(h);
+    if (w>0)
+        SetDisplayWidth(w);
+    if (w==0 && h==0)
+        SetOptimumSize();
 
     //
@@ -997,5 +1012,9 @@
     if (gROOT->IsBatch())
     {
-        TCanvas *c = new TCanvas(name, name);
+        // 4 = 2*default border width of a canvas
+        const UInt_t cw = GetWidth();
+        const UInt_t ch = 2*cw/3 + 25; // 25: Menu, etc
+
+        TCanvas *c = new TCanvas(name, name, -cw, ch);
         fBatch->Add(c);
         return *c;
@@ -1617,30 +1636,33 @@
         return kTRUE;
 
-    case kSize640:  
-        Resize(572, 480);
+    case kSize640:
+        SetDisplaySize(640, 480);
         return kTRUE;
     case kSize768:  
-        Resize(714, 576);
+        SetDisplaySize(768, 576);
         return kTRUE;
     case kSize800:  
-        Resize(750, 600);
+        SetDisplaySize(800, 600);
         return kTRUE;
     case kSize960:  
-        Resize(900, 700);
+        SetDisplaySize(960, 720);
         return kTRUE;
     case kSize1024: 
-        Resize(1000, 768);
+        SetDisplaySize(1024, 768);
         return kTRUE;
     case kSize1152:
-        Resize(1147, 864);
+        SetDisplaySize(1152, 864);
         return kTRUE;
     case kSize1280: 
-        Resize(1321, 980);
+        SetDisplaySize(1280, 1024);
         return kTRUE;
     case kSize1400:
-        Resize(1426, 1050);
+        SetDisplaySize(1400, 1050);
         return kTRUE;
     case kSize1600:
-        Resize(1550, 1400);
+        SetDisplaySize(1600, 1200);
+        return kTRUE;
+    case kSizeOptimum:
+        SetOptimumSize();
         return kTRUE;
 
@@ -2940,4 +2962,133 @@
 }
 
+// --------------------------------------------------------------------------
+//
+//  Change width of display. The height is calculated accordingly.
+//
+void MStatusDisplay::SetDisplayWidth(UInt_t dw)
+{
+    if (gROOT->IsBatch())
+    {
+        SetCanvasWidth(dw);
+        return;
+    }
+
+    // 4 == 2*default border with of canvas
+    dw -= 4;
+
+    // Difference between canvas size and display size
+    const UInt_t cw = GetWidth() -fTab->GetWidth();
+    const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
+
+    const UInt_t dh = TMath::Nint((dw - cw)/1.5 + ch);
+
+    Resize(dw, dh); // Set display size
+}
+
+// --------------------------------------------------------------------------
+//
+//  Change height of display. The width is calculated accordingly.
+//
+void MStatusDisplay::SetDisplayHeight(UInt_t dh)
+{
+    if (gROOT->IsBatch())
+    {
+        SetCanvasHeight(dh);
+        return;
+    }
+
+    // 4 == 2*default border with of canvas
+    dh -= 4;
+
+    // Difference between canvas size and display size
+    const UInt_t cw = GetWidth() -fTab->GetWidth();
+    const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
+
+    const UInt_t dw = TMath::Nint((dh - ch)*1.5 + cw);
+
+    Resize(dw, dh); // Set display size
+}
+
+// --------------------------------------------------------------------------
+//
+//  Change width of canvas. The height is calculated accordingly.
+//
+void MStatusDisplay::SetCanvasWidth(UInt_t w)
+{
+    // 4 == 2*default border with of canvas
+    w += 4;
+
+    if (gROOT->IsBatch())
+    {
+        Resize(w, 3*w/2);
+        return;
+    }
+
+    // Difference between canvas size and display size
+    const UInt_t cw = GetWidth() -fTab->GetWidth();
+    const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
+
+    const UInt_t h  = TMath::Nint(w/1.5 + ch);
+
+    Resize(w + cw, h); // Set display size
+}
+
+// --------------------------------------------------------------------------
+//
+//  Change height of canvas. The width is calculated accordingly.
+//
+void MStatusDisplay::SetCanvasHeight(UInt_t h)
+{
+    // 4 == 2*default border with of canvas
+    h += 4;
+
+    if (gROOT->IsBatch())
+    {
+        Resize(2*h/3, h);
+        return;
+    }
+
+    // Difference between canvas size and display size
+    const UInt_t cw = GetWidth() -fTab->GetWidth();
+    const UInt_t ch = GetHeight()-fTab->GetHeight()+fTab->GetTabHeight();
+
+    // 4 == 2*default border with of canvas
+    const UInt_t dw  = TMath::Nint((h+4)*1.5 + cw);
+
+    Resize(dw, h + ch); // Set display size
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate width and height of the display such that it fits into the
+// defined box.
+//
+void MStatusDisplay::SetDisplaySize(UInt_t w, UInt_t h)
+{
+    if (gROOT->IsBatch())
+        return;
+
+    SetDisplayHeight(h);
+
+    if (GetWidth()>w)
+        SetDisplayWidth(w);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Calculate an optimum size for the display from the desktop size
+//
+void MStatusDisplay::SetOptimumSize()
+{
+    if (gROOT->IsBatch())
+        return;
+
+    const UInt_t w = TMath::Nint(0.95*gClient->GetDisplayWidth());
+    const UInt_t h = TMath::Nint(0.95*gClient->GetDisplayHeight());
+
+    SetDisplaySize(w, h);
+}
+
+
 Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
 {
@@ -2951,6 +3102,6 @@
     UInt_t h = evt->fHeight;
 
-    const Bool_t wchanged = w!=GetWidth();
-    const Bool_t hchanged = h!=GetHeight();
+    const Bool_t wchanged = w!=GetWidth()-fTab->GetWidth();
+    const Bool_t hchanged = h!=GetHeight()-fTab->GetHeight();
 
     if (!wchanged && !hchanged)
Index: trunk/MagicSoft/Mars/mbase/MStatusDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MStatusDisplay.h	(revision 7826)
+++ trunk/MagicSoft/Mars/mbase/MStatusDisplay.h	(revision 7827)
@@ -59,5 +59,5 @@
         // kSize
         kSize640, kSize768, kSize800, kSize960, kSize1024, kSize1152,
-        kSize1280, kSize1400, kSize1600,
+        kSize1280, kSize1400, kSize1600, kSizeOptimum,
         // kLog
         kLogCopy, kLogClear, kLogSelect, kLogFind, kLogSave, kLogAppend,
@@ -157,5 +157,5 @@
 
 public:
-     MStatusDisplay(Long_t t=1000);
+     MStatusDisplay(Int_t w=-1, Int_t h=-1, Long_t t=1000);
      virtual ~MStatusDisplay();
 
@@ -246,4 +246,14 @@
      Bool_t SaveLogAsPS(const char *name) const;
 
+     // Size options
+     void SetCanvasWidth(UInt_t w);
+     void SetCanvasHeight(UInt_t h);
+
+     void SetDisplayWidth(UInt_t w);
+     void SetDisplayHeight(UInt_t h);
+
+     void SetOptimumSize();
+     void SetDisplaySize(UInt_t w, UInt_t h);
+
      Int_t  SaveAs(Int_t num=-1);
      Int_t  Open(TString fname, const char *name="MStatusDisplay");
