Index: trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2026)
+++ trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2052)
@@ -31,4 +31,8 @@
 // (see Read and Write) or printed as a postscript file (see SaveAsPS).
 //
+// To write gif files of C-Macros use SaveAsGif() or SaveAsC().
+// Direct printing to the default printer (via lpr) can be done by
+// PrintToLpr().
+//
 // It has also to half status lines which can be used to display the status
 // or something going on. Together with the status lines it has a progress
@@ -101,11 +105,11 @@
     // filemenu->AddEntry("S&ave [F2]", kFileSave);
     // filemenu->AddEntry("Save &As... [Shift-F2]", kFileSaveAs);
-    filemenu->AddEntry("Save As status.&ps", kFileSaveAsPS);
-    // filemenu->AddEntry("Save As status.&gif", kFileSaveAsGIF);
-    // filemenu->AddEntry("Save As status.&C", kFileSaveAsC);
+    filemenu->AddEntry("Save As status.&ps",   kFileSaveAsPS);
+    filemenu->AddEntry("Save As status.&gif",  kFileSaveAsGIF);
+    filemenu->AddEntry("Save As status.&C",    kFileSaveAsC);
     filemenu->AddEntry("Save As status.&root", kFileSaveAsRoot);
     filemenu->AddSeparator();
-    filemenu->AddEntry("Print with &lpr", kFilePrint);
-    filemenu->AddEntry("Set printer &name", kFilePrinterName);
+    filemenu->AddEntry("Print with &lpr",      kFilePrint);
+    filemenu->AddEntry("Set printer &name",    kFilePrinterName);
     filemenu->AddSeparator();
     filemenu->AddEntry("E&xit", kFileExit);
@@ -118,13 +122,13 @@
     // tabmenu->AddEntry("S&ave [F2]", kFileSave);
     // tabmenu->AddEntry("Save &As... [Shift-F2]", kFileSaveAs);
-    tabmenu->AddEntry("Save As tab-i.&ps", kTabSaveAsPS);
-    // tabmenu->AddEntry("Save As tab-i.&gif", kTabSaveAsGIF);
-    // tabmenu->AddEntry("Save As tab-i.&C", kTabSaveAsC);
+    tabmenu->AddEntry("Save As tab-i.&ps",   kTabSaveAsPS);
+    tabmenu->AddEntry("Save As tab-i.&gif",  kTabSaveAsGIF);
+    tabmenu->AddEntry("Save As tab-i.&C",    kTabSaveAsC);
     tabmenu->AddEntry("Save As tab-i.&root", kTabSaveAsRoot);
     tabmenu->AddSeparator();
-    tabmenu->AddEntry("Print with &lpr", kFilePrint);
+    tabmenu->AddEntry("Print with &lpr",     kFilePrint);
     tabmenu->AddSeparator();
-    tabmenu->AddEntry("Next [&+]",     kTabNext);
-    tabmenu->AddEntry("Previous [&-]", kTabPrevious);
+    tabmenu->AddEntry("Next [&+]",           kTabNext);
+    tabmenu->AddEntry("Previous [&-]",       kTabPrevious);
     tabmenu->Associate(this);
 
@@ -135,4 +139,15 @@
     loopmenu->AddEntry("&Stop", kLoopStop);
     loopmenu->Associate(this);
+
+    //
+    // Loop Menu
+    //
+    MGPopupMenu *sizemenu = new MGPopupMenu(gClient->GetRoot());
+    sizemenu->AddEntry("Fit to 640x&480",   kSize640);
+    sizemenu->AddEntry("Fit to 800x&600",   kSize800);
+    sizemenu->AddEntry("Fit to 960x7&20",   kSize960);
+    sizemenu->AddEntry("Fit to 1024x&768",  kSize1024);
+    sizemenu->AddEntry("Fit to 1280x&1024", kSize1280);
+    sizemenu->Associate(this);
 
     //
@@ -143,4 +158,5 @@
     menubar->AddPopup("&Tab",  tabmenu,  NULL);
     menubar->AddPopup("&Loop", loopmenu, NULL);
+    menubar->AddPopup("&Size", sizemenu, NULL);
     menubar->BindKeys(this);
     AddFrame(menubar);
@@ -160,4 +176,5 @@
     fList->Add(filemenu);
     fList->Add(loopmenu);
+    fList->Add(sizemenu);
     fList->Add(menubar);
     fList->Add(tabmenu);
@@ -175,6 +192,5 @@
 
     // Add MARS version
-    TString txt = "Official Release: V";
-    TGLabel *l = new TGLabel(f, txt+MARSVER);
+    TGLabel *l = new TGLabel(f, Form("Official Release: V%s", MARSVER));
     fList->Add(l);
 
@@ -184,6 +200,5 @@
 
     // Add root version
-    txt = "Using ROOT v";
-    l = new TGLabel(f, txt+ROOTVER);
+    l = new TGLabel(f, Form("Using ROOT v%s", ROOTVER));
     fList->Add(l);
 
@@ -238,10 +253,10 @@
         TGCompositeFrame *f = fTab->AddTab("-Logbook-");
 
-        // Create TGListBox for logging contents
-        fLogBox = new TGListBox(f, 1, 1);
-        fLogBox->ChangeBackground(TGFrame::GetBlackPixel());
+        // Create TGListBox(p, id=-1, opt, back) for logging contents
+        fLogBox = new TGListBox(f, -1, kSunkenFrame);
+        //fLogBox->Associate(this);
 
         // Add List box to the tab
-        TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY);//, 5, 6, 5);
+        TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY,2,2,2,2);
         f->AddFrame(fLogBox, lay);
 
@@ -373,9 +388,5 @@
 void MStatusDisplay::SetStatusLine2(const MParContainer &cont)
 {
-    TString txt = cont.GetDescriptor();
-    txt += ": ";
-    txt += cont.GetTitle();
-
-    SetStatusLine2(txt);
+    SetStatusLine2(Form("%s: %s", cont.GetDescriptor(), cont.GetTitle()));
 }
 
@@ -406,6 +417,8 @@
     // set the smallest and biggest size of the Main frame
     // and move it to its appearance position
-    SetWMSizeHints(640, 548, 1280, 1024, 10, 10);
+    SetWMSizeHints(570, 480, 1280, 980, 1, 1);
     Move(rand()%100+50, rand()%100+50);
+    //Resize(740, 600);
+    Resize(570, 480);
 
     //
@@ -603,5 +616,5 @@
 // via SetPrinter 'lpr -Pname' is used.
 //
-Int_t MStatusDisplay::PrintToLpr(Int_t num) const
+Int_t MStatusDisplay::PrintToLpr(Int_t num)
 {
     TString name = "mars";
@@ -613,7 +626,12 @@
 
     const Int_t pages = SaveAsPS(num, name);
+
+    SetStatusLine1("Printing...");
+    SetStatusLine2("");
+
     if (!pages)
     {
         *fLog << warn << "MStatusDisplay::PrintToLpr: Sorry, couldn't save file as temporary postscript!" << endl;
+        SetStatusLine2("Failed!");
         return 0;
     }
@@ -630,4 +648,6 @@
     gSystem->Exec(cmd);
     gSystem->Unlink(name);
+
+    SetStatusLine2(Form("Done (%dpages)", pages));
 
     return pages;
@@ -658,18 +678,15 @@
 */
     case kFileSaveAsPS:
-        //cout << "FileSaveAsPS..." << endl;
         SaveAsPS();
         return kTRUE;
-/*
+
     case kFileSaveAsGIF:
-        cout << "FileSaveAsGIF..." << endl;
         SaveAsGIF();
         return kTRUE;
 
     case kFileSaveAsC:
-        cout << "FileSaveAsC..." << endl;
         SaveAsC();
         return kTRUE;
-*/
+
     case kFileSaveAsRoot:
         SaveAsRoot();
@@ -683,15 +700,13 @@
         SaveAsPS(fTab->GetCurrent());
         return kTRUE;
-/*
+
     case kTabSaveAsGIF:
-        cout << "TabSaveAsGIF... " << fTab->GetCurrent() <<  endl;
         SaveAsGIF(fTab->GetCurrent());
         return kTRUE;
 
     case kTabSaveAsC:
-        cout << "TabSaveAsC... " << fTab->GetCurrent() <<  endl;
         SaveAsC(fTab->GetCurrent());
         return kTRUE;
-*/
+
     case kTabSaveAsRoot:
         SaveAsRoot(fTab->GetCurrent());
@@ -710,6 +725,22 @@
         return kTRUE;
 
+    case kSize640:
+        Resize(570, 480);
+        return kTRUE;
+    case kSize800:
+        Resize(740, 600);
+        return kTRUE;
+    case kSize960:
+        Resize(880, 700);
+        return kTRUE;
+    case kSize1024:
+        Resize(980, 768);
+        return kTRUE;
+    case kSize1280:
+        Resize(1280, 980);
+        return kTRUE;
+
     default:
-        cout << "Command-Menu: Id=" << id << endl;
+        cout << "Command-Menu #" << id << endl;
     }
     return kTRUE;
@@ -726,8 +757,28 @@
     {
     case kCM_MENU:
-        return ProcessMessageCommandMenu(mp1);
+        return ProcessMessageCommandMenu(mp1); // mp2=userdata
 
     case kCM_MENUSELECT:
-        cout << "Menuselect #" << mp1 << endl;
+        cout << "Command-Menuselect #" << mp1 << " (UserData=" << (void*)mp2 << ")" << endl;
+        return kTRUE;
+
+    case kCM_BUTTON:
+        cout << "Command-Button." << endl;
+        return kTRUE;
+
+    case kCM_CHECKBUTTON:
+        cout << "Command-CheckButton." << endl;
+        return kTRUE;
+
+    case kCM_RADIOBUTTON:
+        cout << "Command-RadioButton." << endl;
+        return kTRUE;
+
+    case kCM_LISTBOX:
+        cout << "Command-Listbox #" << mp1 << " (LineId #" << mp2 << ")" << endl;
+        return kTRUE;
+
+    case kCM_COMBOBOX:
+        cout << "Command-ComboBox." << endl;
         return kTRUE;
 
@@ -764,4 +815,5 @@
 Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
 {
+    // Can be found in WidgetMessageTypes.h
     switch (GET_MSG(msg))
     {
@@ -1005,4 +1057,5 @@
     TObject *obj;
 
+    // See also TPad::UseCurrentStyle
     TIter Next(p.GetListOfPrimitives());
     while ((obj=Next()))
@@ -1036,4 +1089,24 @@
 }
 
+Bool_t MStatusDisplay::CheckTabForCanvas(int num) const
+{
+    if (num>=fTab->GetNumberOfTabs())
+    {
+        *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
+        return kFALSE;
+    }
+    if (num==0)
+    {
+        *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
+        return kFALSE;
+    }
+    if (fTab->GetNumberOfTabs()<2 || !gPad)
+    {
+        *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
+        return kFALSE;
+    }
+    return kTRUE;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -1046,19 +1119,12 @@
 // To write all tabs you can also use SaveAsPS(name)
 //
-Int_t MStatusDisplay::SaveAsPS(Int_t num, TString name) const
-{
-    if (num>=fTab->GetNumberOfTabs())
-    {
-        *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
-        return 0;
-    }
-    if (num==0)
-    {
-        *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
-        return 0;
-    }
-    if (fTab->GetNumberOfTabs()<2 || !gPad)
-    {
-        *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
+Int_t MStatusDisplay::SaveAsPS(Int_t num, TString name)
+{
+    SetStatusLine1("Writing Postscript file...");
+    SetStatusLine2("");
+
+    if (!CheckTabForCanvas(num))
+    {
+        SetStatusLine2("Failed!");
         return 0;
     }
@@ -1107,4 +1173,6 @@
             continue;
         }
+
+        SetStatusLine2(Form("Tab #%d", i));
 
         //
@@ -1186,24 +1254,171 @@
     *fLog << inf << "done." << endl;
 
+    SetStatusLine2(Form("Done (%dpages)", page-1));
+
     return page-1;
 }
 
-/*
-void MStatusDisplay::SaveAsGIF(Int_t num, TString name) const
-{
+Bool_t MStatusDisplay::SaveAsGIF(Int_t num, TString name)
+{
+    SetStatusLine1("Writing GIF file...");
+    SetStatusLine2("");
+
+    if (!CheckTabForCanvas(num))
+    {
+        SetStatusLine2("Failed!");
+        return 0;
+    }
+
     AddExtension(name, "gif", num);
 
-    cout << "Open gif-File: " << name << endl;
-    cout << " SORRY, not implemented." << endl;
-}
-
-void MStatusDisplay::SaveAsC(Int_t num, TString name) const
-{
+    if (num<0)
+        *fLog << inf << "Writing gif-Files..." << endl;
+
+    TPad *padsav = (TPad*)gPad;
+
+    int page = 1;
+
+    //
+    // Maintain tab numbers
+    //
+    const Int_t from = num<0 ? 1 : num;
+    const Int_t to   = num<0 ? fTab->GetNumberOfTabs() : num+1;
+
+    for (int i=from; i<to; i++)
+    {
+        TCanvas *c;
+        if (!(c = GetCanvas(i)))
+        {
+            if (num<0)
+                *fLog << inf << " - ";
+            *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
+            continue;
+        }
+
+        SetStatusLine2(Form("Tab #%d", i));
+
+        //
+        // Clone canvas and change background color and schedule for
+        // deletion
+        //
+        //TCanvas *n = (TCanvas*)c->Clone();
+        //CanvasSetFillColor(*n, kWhite);
+
+        //
+        // Paint canvas into root file
+        //
+        TString writename = name;
+        if (num<0)
+        {
+            TString numname = "-";
+            numname += i;
+            writename.Insert(name.Last('.'), numname);
+        }
+        if (num<0)
+            *fLog << inf << " - ";
+        *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << c << ") ";
+        if (num>0)
+            *fLog << "to " << name;
+        *fLog << "..." << flush;
+
+        c->Draw();
+        c->SaveAs(writename);
+        /*
+         n->Draw();
+         n->SaveAs(writename);
+         delete n;
+         */
+
+        if (num<0)
+            *fLog << "done." << endl;
+    }
+
+    padsav->cd();
+
+    *fLog << inf << "done." << endl;
+
+    SetStatusLine2("Done.");
+
+    return page-1;
+}
+
+Bool_t MStatusDisplay::SaveAsC(Int_t num, TString name)
+{
+    SetStatusLine1("Writing C++ file...");
+    SetStatusLine2("");
+
+    if (!CheckTabForCanvas(num))
+    {
+        SetStatusLine2("Failed!");
+        return 0;
+    }
+
     AddExtension(name, "C", num);
 
-    cout << "Open C-File: " << name << endl;
-    cout << " SORRY, not implemented." << endl;
-}
-*/
+    if (num<0)
+        *fLog << inf << "Writing C-Files..." << endl;
+
+    TPad *padsav = (TPad*)gPad;
+
+    int page = 1;
+
+    //
+    // Maintain tab numbers
+    //
+    const Int_t from = num<0 ? 1 : num;
+    const Int_t to   = num<0 ? fTab->GetNumberOfTabs() : num+1;
+
+    for (int i=from; i<to; i++)
+    {
+        TCanvas *c;
+        if (!(c = GetCanvas(i)))
+        {
+            if (num<0)
+                *fLog << inf << " - ";
+            *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
+            continue;
+        }
+
+        SetStatusLine2(Form("Tab #%d", i));
+
+        //
+        // Clone canvas and change background color and schedule for
+        // deletion
+        //
+        TCanvas *n = (TCanvas*)c->Clone();
+        CanvasSetFillColor(*n, kWhite);
+
+        //
+        // Paint canvas into root file
+        //
+        TString writename = name;
+        if (num<0)
+        {
+            TString numname = "-";
+            numname += i;
+            writename.Insert(name.Last('.'), numname);
+        }
+        if (num<0)
+            *fLog << inf << " - ";
+        *fLog << inf << "Writing Tab #" << i << " to " << writename << ": " << c->GetName() << " (" << n << ") ";
+        if (num>0)
+            *fLog << "to " << name;
+        *fLog << "..." << flush;
+
+        n->SaveSource(writename, "");
+        delete n;
+
+        if (num<0)
+            *fLog << "done." << endl;
+    }
+
+    padsav->cd();
+
+    *fLog << inf << "done." << endl;
+
+    SetStatusLine2("Done.");
+
+    return page-1;
+}
 
 // --------------------------------------------------------------------------
@@ -1219,17 +1434,10 @@
 Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name)
 {
-    if (num>=fTab->GetNumberOfTabs())
-    {
-        *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
-        return 0;
-    }
-    if (num==0)
-    {
-        *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
-        return 0;
-    }
-    if (fTab->GetNumberOfTabs()<2 || !gPad)
-    {
-        *fLog << warn << "Sorry, you must have at least one existing canvas." << endl;
+    SetStatusLine1("Writing root file...");
+    SetStatusLine2("");
+
+    if (!CheckTabForCanvas(num))
+    {
+        SetStatusLine2("Failed!");
         return 0;
     }
@@ -1242,4 +1450,70 @@
     gFile = fsave;
 
+    SetStatusLine2("Done.");
+
     return keys;
 }
+
+Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt)
+{
+    //cout << "----- Start -----" << endl;
+
+    UInt_t w = evt->fWidth;
+    UInt_t h = evt->fHeight;
+
+    //cout << "Old: " << GetWidth() << " " << GetHeight() << " " << GetBorderWidth() << endl;
+    //cout << "New: " << w << " " << h << endl;
+
+    Bool_t wchanged = w!=GetWidth();
+    Bool_t hchanged = h!=GetHeight();
+
+    if (!wchanged && !hchanged)
+    {
+        Layout();
+        return kTRUE;
+    }
+
+    if (GetWidth()==1 && GetHeight()==1)
+        return kTRUE;
+
+    // calculate the constant part of the window
+    const UInt_t cw = GetWidth() -fTab->GetWidth();
+    const UInt_t ch = GetHeight()-fTab->GetHeight();
+
+    // canculate new size of frame (canvas @ 1:sqrt(2))
+    if (hchanged)
+        w = (UInt_t)((h-ch)*sqrt(2)+.5)+cw;
+    else
+        h = (UInt_t)((w-cw)/sqrt(2)+.5)+ch;
+
+    //cout << "Res: " << w << " " << h << " " << evt->fX << " " << evt->fY << endl;
+
+    // resize frame
+    Resize(w, h);
+
+    return kTRUE;
+}
+
+Bool_t MStatusDisplay::HandleEvent(Event_t *event)
+{
+    /*
+    if (event->fType!=9)
+    {
+        cout << "Event: " << event->fType << " ";
+        cout << event->fX << " " << event->fY << endl;
+    }
+    */
+    /*
+    switch (event->fType) {
+      case kConfigureNotify:
+         //while (gVirtualX->CheckEvent(fId, kConfigureNotify, *event))
+         //   ;
+         HandleConfigureNotify(event);
+         return kTRUE;
+    }
+    */
+    //   if (event->fType==kConfigureNotify && event->fX!=0 && event->fY!=0)
+    //        return kTRUE;
+
+    return TGMainFrame::HandleEvent(event);
+}
Index: trunk/MagicSoft/Mars/mmain/MStatusDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MStatusDisplay.h	(revision 2026)
+++ trunk/MagicSoft/Mars/mmain/MStatusDisplay.h	(revision 2052)
@@ -51,4 +51,9 @@
         kTabNext,
         kTabPrevious,
+        kSize640,
+        kSize800,
+        kSize960,
+        kSize1024,
+        kSize1280,
         kFileExit,
         kPicMagic,
@@ -89,4 +94,6 @@
     Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
     void   CloseWindow();
+    Bool_t HandleConfigureNotify(Event_t *);
+    Bool_t HandleEvent(Event_t *event);
 
     Bool_t HandleTimer(TTimer *timer=NULL);
@@ -135,15 +142,15 @@
      void SetNoContextMenu(Bool_t flag=kTRUE);
 
-     Int_t SaveAsPS(TString name="") const { return SaveAsPS(-1, name); }
-     //Bool_t SaveAsGIF(TString name="") const { return SaveAsGIF(-1, name); }
-     //Bool_t SaveAsC(TString name="") const { return SaveAsC(-1, name); }
-     Int_t SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); }
-     Int_t PrintToLpr() const { return PrintToLpr(-1); }
+     Int_t  SaveAsPS(TString name="") { return SaveAsPS(-1, name); }
+     Bool_t SaveAsGIF(TString name="") { return SaveAsGIF(-1, name); }
+     Bool_t SaveAsC(TString name="") { return SaveAsC(-1, name); }
+     Int_t  SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); }
+     Int_t  PrintToLpr() { return PrintToLpr(-1); }
 
-     Int_t SaveAsPS(Int_t num, TString name="") const;
-     //Bool_t SaveAsGIF(Int_t num, TString name="") const;
-     //Bool_t SaveAsC(Int_t num, TString name="") const;
-     Int_t SaveAsRoot(Int_t num, TString name="");
-     Int_t PrintToLpr(Int_t num) const;
+     Int_t  SaveAsPS(Int_t num, TString name="");
+     Bool_t SaveAsGIF(Int_t num, TString name="");
+     Bool_t SaveAsC(Int_t num, TString name="");
+     Int_t  SaveAsRoot(Int_t num, TString name="");
+     Int_t  PrintToLpr(Int_t num);
 
      Status_t CheckStatus() const { return fStatus; }
@@ -153,4 +160,6 @@
      void UnLock() { ResetBit(kIsLocked); }
 
+     Bool_t CheckTabForCanvas(int num) const;
+
      ClassDef(MStatusDisplay, 0)   // Window for a status display
 };
