Index: trunk/MagicSoft/Mars/meventdisp/MGEvtDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/meventdisp/MGEvtDisplay.cc	(revision 1015)
+++ trunk/MagicSoft/Mars/meventdisp/MGEvtDisplay.cc	(revision 1023)
@@ -28,8 +28,11 @@
 
 #include <TGTab.h>                // TGTab
+#include <TGMenu.h>               // TGPopupMenu
+#include <TCanvas.h>              // TCanvas::Print
 #include <TGLabel.h>              // TGLabel
 #include <TGButton.h>             // TGPictureButton
 #include <TGMsgBox.h>             // TGMsgBox
 #include <TGTextEntry.h>          // TGTextEntry
+#include <TGFileDialog.h>         // TGFileDialog
 #include <TRootEmbeddedCanvas.h>  // TRootEmbeddedCanvas
 
@@ -46,10 +49,16 @@
 enum MGCamDisplayCommand
 {
-    M_PREVEVT,
-    M_NEXTEVT,
-    M_EVTNUMBER,
-
-    M_PRINT,
-    M_CLOSE
+    kEvtPrev,
+    kEvtNext,
+    kEvtNumber,
+
+    kFileSaveAs,
+    kFileSaveAsRoot,
+    kFileSaveAsC,
+    kFileSaveAsPS,
+    kFileSaveAsEPS,
+    kFileSaveAsGIF,
+    kFilePrint,
+    kClose
 }; 
 
@@ -155,10 +164,10 @@
     // Create the gui elements
     //
-    TGTextButton *prevevt = new TGTextButton(top2, "<< Previous Event", M_PREVEVT);
+    TGTextButton *prevevt = new TGTextButton(top2, "<< Previous Event", kEvtPrev);
     prevevt->Associate(this);
 
     TGLabel *evtnr = new TGLabel(top2, new TGString("Event: "));
 
-    fTxtEvtNr = new TGTextEntry(top2, new TGTextBuffer(100), M_EVTNUMBER);
+    fTxtEvtNr = new TGTextEntry(top2, new TGTextBuffer(100), kEvtNumber);
     fTxtEvtNr->Resize(60, fTxtEvtNr->GetDefaultHeight());
     fTxtEvtNr->Associate(this);
@@ -166,5 +175,5 @@
     fNumOfEvts = new TGLabel(top2, "out of           Events.");
 
-    TGTextButton *nextevt = new TGTextButton (top2, "Next Event >>", M_NEXTEVT);
+    TGTextButton *nextevt = new TGTextButton (top2, "Next Event >>", kEvtNext);
     nextevt->Associate(this);
 
@@ -252,18 +261,14 @@
 void MGEvtDisplay::AddLowFrame(TGHorizontalFrame *frame)
 {
-    TGTextButton *but1 = new TGTextButton(frame, "Print", M_PRINT);
-    TGTextButton *but2 = new TGTextButton(frame, "Close", M_CLOSE);
-
-    but1->Associate(this);
-    but2->Associate(this);
-
-    fList->Add(but1);
-    fList->Add(but2);
+    TGTextButton *but = new TGTextButton(frame, "Close", kClose);
+
+    but->Associate(this);
+
+    fList->Add(but);
 
     TGLayoutHints *laybut = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
     fList->Add(laybut);
 
-    frame->AddFrame(but1, laybut);
-    frame->AddFrame(but2, laybut);
+    frame->AddFrame(but, laybut);
 }
 
@@ -330,4 +335,42 @@
 //  Constructor
 //
+void MGEvtDisplay::AddMenuBar()
+{
+    //
+    // Add all GUI elements and update the event counter
+    //
+    TGLayoutHints *laymenubar  = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 2, 2, 2, 2);
+    TGLayoutHints *laymenuitem = new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0);
+    TGLayoutHints *laylinesep  = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
+
+    fList->Add(laymenubar);
+    fList->Add(laymenuitem);
+    fList->Add(laylinesep);
+
+    TGPopupMenu *filemenu = new TGPopupMenu(gClient->GetRoot());
+    filemenu->AddEntry("Save &As...",           kFileSaveAs);
+    filemenu->AddEntry("Save As display.&ps",   kFileSaveAsPS);
+    filemenu->AddEntry("Save As display.&eps",  kFileSaveAsEPS);
+    filemenu->AddEntry("Save As display.&gif",  kFileSaveAsGIF);
+    filemenu->AddEntry("Save As display.&C",    kFileSaveAsC);
+    filemenu->AddEntry("Save As display.&root", kFileSaveAsRoot);
+    filemenu->AddSeparator();
+    filemenu->AddEntry("&Print...", kFilePrint);
+    filemenu->AddSeparator();
+    filemenu->AddEntry("E&xit", kClose);
+    filemenu->Associate(this);
+
+    TGMenuBar *menubar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
+    menubar->AddPopup("File", filemenu, laymenuitem);
+    AddFrame(menubar, laymenubar);
+
+    TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
+    AddFrame(linesep, laylinesep);
+
+    fList->Add(filemenu);
+    fList->Add(menubar);
+    fList->Add(linesep);
+}
+
 MGEvtDisplay::MGEvtDisplay(const char *fname, const char *tname,
                            const TGWindow *p, const TGWindow *main,
@@ -346,5 +389,4 @@
     // (via SetOwner())
     //
-
     MTaskList *tlist = new MTaskList;
     tlist->SetOwner();
@@ -353,5 +395,5 @@
     tlist->AddToList(read);
 
-    MParList *plist = new MParList();
+    MParList *plist = new MParList;
     plist->SetOwner();
     plist->AddToList(tlist);
@@ -361,12 +403,9 @@
     fEvtLoop->SetParList(plist);
 
-    //
-    // Add all GUI elements and update the event counter
-    // 
+    AddMenuBar();
     AddFrames(fname, tname);
     UpdateEventCounter();
 }
 
-
 // --------------------------------------------------------------------------
 //
@@ -375,8 +414,8 @@
 MGEvtDisplay::~MGEvtDisplay()
 {
-    delete fList;
-
     fEvtLoop->PostProcess();
     delete fEvtLoop;
+
+    delete fList;
 }
 
@@ -404,10 +443,10 @@
     Int_t retval  = 0;
 
+    //
     //  first check if the new event is in the range of possible events
-  
+    //
     if (iEvt >= GetReader()->GetEntries())
     {
-        new TGMsgBox(gClient->GetRoot(), this,
-                     "WARNING!",
+        new TGMsgBox(gClient->GetRoot(), this, "WARNING!",
                      "The event number is out of range!!!",
                      kMBIconExclamation, buttons, &retval);
@@ -435,4 +474,52 @@
 
     fTxtEvtNr->SetText(txt);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Opens a save as dialog, and tries to store the canvas
+//  in the given output format
+//
+void MGEvtDisplay::SaveAsDialog() const
+{
+    static const char *gSaveAsTypes[] =
+    {
+        "PostScript",   "*.ps",
+        "Encapsulated PostScript", "*.eps",
+        "Gif files",    "*.gif",
+        "Macro files",  "*.C",
+        "ROOT files",   "*.root",
+        "All files",    "*",
+        NULL,           NULL
+    };
+
+    static TString dir(".");
+
+    TGFileInfo fi;
+
+    fi.fFileTypes = gSaveAsTypes;
+    fi.fIniDir    = StrDup(dir);
+
+    new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
+
+    if (!fi.fFilename)
+        return;
+
+    dir = fi.fIniDir;
+
+    if (strstr(fi.fFilename, ".root") ||
+        strstr(fi.fFilename, ".ps")   ||
+        strstr(fi.fFilename, ".eps")  ||
+        strstr(fi.fFilename, ".gif"))
+    {
+        fCanvas->SaveAs(fi.fFilename);
+        return;
+    }
+    if (strstr(fi.fFilename, ".C"))
+    {
+        fCanvas->SaveSource(fi.fFilename);
+        return;
+    }
+    Warning("SaveAsDialog", "Unknown Extension: %s", fi.fFilename);
 }
 
@@ -456,5 +543,5 @@
             switch (parm1)
             {
-            case M_PREVEVT:
+            case kEvtPrev:
                 //
                 // '-2' is because MReadTree::Process increases the
@@ -465,5 +552,5 @@
                 return kTRUE;
 
-            case M_NEXTEVT:
+            case kEvtNext:
                 //
                 // '+0' is because MReadTree::Process increases the
@@ -474,5 +561,35 @@
                 return kTRUE;
 
-            case M_CLOSE:
+            case kClose:
+                CloseWindow();
+                return kTRUE;
+            }
+            return kTRUE;
+
+        case kCM_MENU:
+            switch (parm1)
+            {
+            case kFileSaveAs:
+                SaveAsDialog();
+                return kTRUE;
+            case kFileSaveAsRoot:
+                fCanvas->SaveAs("display.root");
+                return kTRUE;
+            case kFileSaveAsC:
+                fCanvas->SaveSource("display.C");
+                return kTRUE;
+            case kFileSaveAsPS:
+                fCanvas->SaveAs("display.ps");
+                return kTRUE;
+            case kFileSaveAsEPS:
+                fCanvas->SaveAs("display.eps");
+                return kTRUE;
+            case kFileSaveAsGIF:
+                fCanvas->SaveAs("display.gif");
+                return kTRUE;
+            case kFilePrint:
+                fCanvas->Print();
+                return kTRUE;
+            case kClose:
                 CloseWindow();
                 return kTRUE;
Index: trunk/MagicSoft/Mars/meventdisp/MGEvtDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/meventdisp/MGEvtDisplay.h	(revision 1015)
+++ trunk/MagicSoft/Mars/meventdisp/MGEvtDisplay.h	(revision 1023)
@@ -29,4 +29,5 @@
     TGTextEntry *fTxtEvtNr;
 
+    void AddMenuBar();
     void AddTopFramePart1(TGVerticalFrame *frame,
                           const char *filename,
@@ -37,4 +38,6 @@
 
     void AddFrames(const char *filename, const char *treename);
+
+    void SaveAsDialog() const;
 
     void ReadinEvent(UInt_t iEvt);
