Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 945)
+++ trunk/MagicSoft/Mars/Changelog	(revision 946)
@@ -10,4 +10,9 @@
        
    * mmain/MBrowser.[cc,h]:
+     - reorganized code (constructor)
+     - reorganized deletion of gui objects
+     - fixed many, many memory leaks
+
+   * mmain/MMars.[cc,h]:
      - reorganized code (constructor)
      - reorganized deletion of gui objects
Index: trunk/MagicSoft/Mars/mmain/MMars.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MMars.cc	(revision 945)
+++ trunk/MagicSoft/Mars/mmain/MMars.cc	(revision 946)
@@ -44,122 +44,165 @@
 
 enum {
-  M_FILE_EXIT  ,
-  M_FILE_ABOUT  ,
-
-  M_PICTURE_MAGIC , 
-  M_PICTURE_MARS ,
-
-  M_BUTTON_EVTDISP ,
-  M_BUTTON_DATACHECK ,
-  M_BUTTON_ANALYSE ,
-  M_BUTTON_MONTECARLO 
+  M_FILE_EXIT,
+  M_FILE_ABOUT,
+
+  M_PICTURE_MAGIC,
+  M_PICTURE_MARS,
+
+  M_BUTTON_EVTDISP,
+  M_BUTTON_DATACHECK,
+  M_BUTTON_ANALYSE,
+  M_BUTTON_MONTECARLO
 } ; 
 
+void MMars::CreateMenuBar()
+{
+    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("Exit", M_FILE_EXIT);
+    //fFileMenu->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);
+}
+
+void MMars::CreateTopFrame(TGHorizontalFrame *top)
+{
+    fPic1 = gClient->GetPicture("magiclogo.xpm");
+    fPic2 = gClient->GetPicture("marslogo.xpm");
+
+    TGPictureButton *magic = new TGPictureButton(top, fPic1, M_PICTURE_MAGIC);
+    TGPictureButton *mars  = new TGPictureButton(top, fPic2, M_PICTURE_MARS);
+
+    fList->Add(magic);
+    fList->Add(mars);
+
+    magic->Associate(this);
+    mars->Associate(this);
+
+    TGLayoutHints *lay1 = new TGLayoutHints(kLHintsLeft, 10., 10., 20., 10.);
+    TGLayoutHints *lay2 = new TGLayoutHints(kLHintsLeft, 10., 10., 10., 10.);
+
+    fList->Add(lay1);
+    fList->Add(lay2);
+
+    top->AddFrame(magic, lay1);
+    top->AddFrame(mars,  lay1);
+}
+
+void MMars::CreateBottomFrame(TGHorizontalFrame *low)
+{
+    //
+    // Create Tab Container
+    //
+    TGLayoutHints *laytabs = new TGLayoutHints(kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
+    fList->Add(laytabs);
+
+    TGTab *tabs = new TGTab(low, 400, 400);
+    fList->Add(tabs);
+    low->AddFrame(tabs, laytabs);
+
+    //
+    // Create Tab1
+    //
+    TGCompositeFrame *tf = tabs->AddTab("Control");
+
+    TGVerticalFrame *tab1 = new TGVerticalFrame(tf, 300, 100);
+    TGVerticalFrame *tab2 = new TGVerticalFrame(tf, 300, 100);
+
+    fList->Add(tab1);
+    fList->Add(tab2);
+
+    TGLayoutHints *laytabx = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
+    fList->Add(laytabx);
+
+    tf->AddFrame(tab1, laytabx);
+    tf->AddFrame(tab2, laytabx);
+
+    TGTextButton *evtdisp    = new TGTextButton(tab2, "EventDisplay", M_BUTTON_EVTDISP);
+    TGTextButton *datacheck  = new TGTextButton(tab2, "Data Check",   M_BUTTON_DATACHECK);
+    TGTextButton *analysis   = new TGTextButton(tab2, "Analysis",     M_BUTTON_ANALYSE);
+    TGTextButton *montecarlo = new TGTextButton(tab2, "MonteCarlo",   M_BUTTON_MONTECARLO);
+
+    fList->Add(evtdisp);
+    fList->Add(datacheck);
+    fList->Add(analysis);
+    fList->Add(montecarlo);
+
+    evtdisp   ->Associate(this);
+    datacheck ->Associate(this);
+    analysis  ->Associate(this);
+    montecarlo->Associate(this);
+
+    TGLayoutHints *laybut = new TGLayoutHints(kLHintsTop|kLHintsCenterX , 10, 10, 10, 10);
+    fList->Add(laybut);
+
+    tab2->AddFrame(evtdisp,    laybut);
+    tab2->AddFrame(datacheck,  laybut);
+    tab2->AddFrame(analysis,   laybut);
+    tab2->AddFrame(montecarlo, laybut);
+}
 
 MMars::MMars(/*const TGWindow *p,*/ UInt_t w, UInt_t h)
   : TGMainFrame(gClient->GetRoot(), w, h)
-{ 
-  //    First create the MenuBar.   
-  
-  //     Layout objects for menue. 
-
-  fLayMenuBar = new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2 ) ; 
-  fLayMenuItem = new TGLayoutHints ( kLHintsTop | kLHintsLeft , 0, 4, 0, 0 ) ; 
-  
-  //  crate the menu bar
-  
-  fFileMenu = new TGPopupMenu ( fClient->GetRoot() ) ; 
-  fFileMenu->AddEntry ("Exit", M_FILE_EXIT ) ; 
-  fFileMenu->Associate(this) ; 
-  
-  //  the button messages are handled by main frame (this) 
-  
-  fMenuBar = new TGMenuBar ( this, 1, 1, kHorizontalFrame ) ; 
-  fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem ) ;   
-  AddFrame(fMenuBar, fLayMenuBar ) ; 
-
-  fLineSep = new TGHorizontal3DLine(this) ; 
-  AddFrame(fLineSep, new TGLayoutHints(kLHintsTop | kLHintsExpandX) );
-  
-  //   set up the top part of the main window with the logos
-
-  fTop = new TGHorizontalFrame (this, 300, 100 ) ;
-
-  fPicMagic = new TGPictureButton(fTop, 
-                                  gClient->GetPicture("magiclogo.xpm"), M_PICTURE_MAGIC );
-  fPicMagic->Associate(this) ; 
-  fTop->AddFrame ( fPicMagic, new TGLayoutHints(kLHintsLeft, 10., 10., 20., 10.) ) ; 
-
-  fPicMars = new TGPictureButton(fTop, 
-				 gClient->GetPicture("marslogo.xpm"), M_PICTURE_MARS );
-  fPicMars->Associate(this) ;
-  fTop->AddFrame ( fPicMars, new TGLayoutHints(kLHintsLeft, 10., 10., 10., 10.) ) ; 
-
-  AddFrame(fTop, new TGLayoutHints(kLHintsTop | kLHintsExpandX ) );  
-  
-  //  a seperator 
-
-  fLineSep2 = new TGHorizontal3DLine(this) ; 
-  AddFrame(fLineSep2, new TGLayoutHints(kLHintsTop | kLHintsExpandX) );
-
-  //   the low part of the frame 
-
-  fLow = new TGHorizontalFrame (this, 300, 100 ) ;
-
-  //    create the first tab
-
-  fTab = new TGTab ( fLow, 400, 400 ) ;   
-
-  TGCompositeFrame *tf = fTab->AddTab("Control") ; 
- 
-  fTabF1 = new TGVerticalFrame (tf, 300, 100) ; 
-
-  tf->AddFrame(fTabF1, new TGLayoutHints(kLHintsTop | kLHintsExpandX) ) ; 
-
-  //     the buttons to go in the new window
-
-  fTabF2 = new TGVerticalFrame (tf, 300, 100) ; 
-  
-  fButLayout  = new TGLayoutHints(kLHintsTop | kLHintsCenterX , 10, 10, 10, 10) ; 
-
-  fButEvtDisp = new TGTextButton(fTabF2, "EventDisplay", M_BUTTON_EVTDISP  );
-  fButEvtDisp->Associate(this) ;  
-  fTabF2->AddFrame(fButEvtDisp, fButLayout ) ; 
- 
-  fButDataCheck = new TGTextButton(fTabF2, "Data Check", M_BUTTON_DATACHECK  );
-  fButDataCheck->Associate(this) ;
-  fTabF2->AddFrame(fButDataCheck, fButLayout ) ; 
-
-  fButAnalys = new TGTextButton(fTabF2, "Analysis", M_BUTTON_ANALYSE  );
-  fButAnalys->Associate(this) ;
-  fTabF2->AddFrame(fButAnalys, fButLayout ) ; 
-
-  fButMonteCarlo = new TGTextButton(fTabF2, "MonteCarlo", M_BUTTON_MONTECARLO  );
-  fButMonteCarlo->Associate(this) ;
-  fTabF2->AddFrame(fButMonteCarlo, fButLayout ) ; 
-
-
-   
-
-  tf->AddFrame(fTabF2, new TGLayoutHints(kLHintsTop | kLHintsExpandX) ) ; 
-  
-  
-
-  fLow->AddFrame ( fTab, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) );   
-  AddFrame(fLow, new TGLayoutHints(kLHintsTop | kLHintsExpandX ) );
-  
-  //   Map the window, set up the layout, etc. 
-  
-  SetWMSizeHints(400, 650, 1000, 1000, 10, 10 ) ;  // set the smallest and biggest size of the Main frame
-  
-  MapSubwindows();
-  
-  Layout();
-  
-  SetWindowName("MARS Main Window");
-  SetIconName("MARS");
-  
-  MapWindow();
-
+{
+    //
+    // Create the deletion list
+    //
+    fList = new TList;
+    fList->SetOwner();
+
+    //
+    // Create the MenuBar
+    //
+    CreateMenuBar();
+
+    //
+    // create and layout the frame/contents
+    //
+    TGHorizontalFrame *top = new TGHorizontalFrame(this, 300, 100);
+    TGHorizontalFrame *low = new TGHorizontalFrame(this, 300, 100);
+
+    TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
+
+    fList->Add(top);
+    fList->Add(low);
+    fList->Add(linesep);
+
+    CreateTopFrame(top);
+    CreateBottomFrame(low);
+
+    AddFrame(top,     new TGLayoutHints(kLHintsTop|kLHintsExpandX));
+    AddFrame(linesep, new TGLayoutHints(kLHintsTop|kLHintsExpandX));
+    AddFrame(low,     new TGLayoutHints(kLHintsTop|kLHintsExpandX));
+
+    //
+    //   Map the window, set up the layout, etc.
+    //
+    SetWMSizeHints(400, 650, 1000, 1000, 10, 10 ) ;  // set the smallest and biggest size of the Main frame
+
+    MapSubwindows();
+
+    Layout();
+
+    SetWindowName("MARS Main Window");
+    SetIconName("MARS");
+
+    MapWindow();
 } 
 
@@ -168,23 +211,8 @@
 MMars::~MMars()
 {
-  
-    delete fButLayout;
-    delete fLayMenuBar;
-    delete fLayMenuItem;
-    delete fButEvtDisp;
-    delete fButDataCheck;
-    delete fButAnalys;
-    delete fButMonteCarlo;
-    delete fPicMagic;
-    delete fPicMars;
-    delete fTabF1;
-    delete fTabF2;
-    delete fTab;
-    delete fLow;
-    delete fTop;
-    delete fLineSep2;
-    delete fLineSep;
-    delete fFileMenu;
-    delete fMenuBar;
+    gClient->FreePicture(fPic1);
+    gClient->FreePicture(fPic2);
+
+    delete fList;
 }  
 // ======================================================================
@@ -198,5 +226,5 @@
 
    TGMainFrame::CloseWindow();
-   gROOT->GetApplication()->Terminate(0)  ; 
+   gROOT->GetApplication()->Terminate(0);
 }
 
@@ -253,5 +281,5 @@
                 return kTRUE;
 
-            CloseWindow() ;
+            CloseWindow();
             return kTRUE;
 	}
Index: trunk/MagicSoft/Mars/mmain/MMars.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MMars.h	(revision 945)
+++ trunk/MagicSoft/Mars/mmain/MMars.h	(revision 946)
@@ -10,62 +10,32 @@
 #endif
 
-class TGTab;
-class TGMenuBar;
-class TGPopupMenu;
-class TGTextButton;
-class TGPictureButton;
-class TGHorizontal3DLine;
+class TList;
 
-class MMars : public TGMainFrame {
- private:
-  
-  //
-  // Create a main frame with a number of different buttons.
-  //
+class MMars : public TGMainFrame
+{
+private:
 
-  //  the things for the menu bar 
-    
-  TGMenuBar          *fMenuBar ;
-  TGPopupMenu        *fFileMenu ;
-  TGLayoutHints      *fLayMenuBar;
-  TGLayoutHints      *fLayMenuItem ;
-  TGHorizontal3DLine *fLineSep ; 
+    TList *fList;
 
-  //   divide the Window in two different parts
-  
-  TGHorizontalFrame  *fTop ;   // top part of the main window
-  TGHorizontal3DLine *fLineSep2 ;
-  TGHorizontalFrame  *fLow ;   // low part of the main window
-  TGTab              *fTab ;   // different tabs in the low window
-  
-  //   the object in the top part of the frame
-  
-  TGPictureButton  *fPicMagic;
-  TGPictureButton  *fPicMars ;
- 
-  //   the object in the low part of the frame
- 
-  TGVerticalFrame  *fTabF1; 
-  TGVerticalFrame  *fTabF2 ;
-  
-  TGTextButton     *fButEvtDisp;
-  TGTextButton     *fButDataCheck;
-  TGTextButton     *fButAnalys;
-  TGTextButton     *fButMonteCarlo ;
-  TGLayoutHints    *fButLayout ; 
+    const TGPicture *fPic1;
+    const TGPicture *fPic2;
 
-  void DisplWarning(const char *txt);
+    void CreateMenuBar();
+    void CreateTopFrame(TGHorizontalFrame *top);
+    void CreateBottomFrame(TGHorizontalFrame *low);
 
- public: 
-  MMars(UInt_t w=400, UInt_t h=500) ;
-  
-  ~MMars(); 
-  
-  void CloseWindow()  ; 
+    void DisplWarning(const char *txt);
 
-  Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
+public:
+    MMars(UInt_t w=400, UInt_t h=500);
 
-  ClassDef(MMars, 0) // GUI: Mars - the main window
-} ; 
+    ~MMars();
+
+    void CloseWindow();
+
+    Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
+
+    ClassDef(MMars, 0) // GUI: Mars - the main window
+};
 
 #endif
