Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 944)
+++ trunk/MagicSoft/Mars/Changelog	(revision 945)
@@ -8,4 +8,9 @@
        people triing to commit changed files from such an archive to
        the repository
+       
+   * mmain/MBrowser.[cc,h]:
+     - reorganized code (constructor)
+     - reorganized deletion of gui objects
+     - fixed many, many memory leaks
 
 
Index: trunk/MagicSoft/Mars/mmain/MBrowser.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MBrowser.cc	(revision 944)
+++ trunk/MagicSoft/Mars/mmain/MBrowser.cc	(revision 945)
@@ -50,4 +50,177 @@
 };
 
+void MBrowser::CreateMenuBar()
+{
+    //
+    //  crate the menu bar
+    //
+    TGPopupMenu *filemenu = new TGPopupMenu(gClient->GetRoot());
+    filemenu->AddEntry("Close", M_FILE_CLOSE);
+    //filemenu->Associate(this);
+    fList->Add(filemenu);
+
+    //
+    //  the button messages are handled by main frame (this)
+    //
+    TGLayoutHints *laymenubar  = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 2, 2, 2, 2);
+    TGLayoutHints *laymenuitem = new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0);
+
+    fList->Add(laymenubar);
+    fList->Add(laymenuitem);
+
+    TGMenuBar *menubar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
+    menubar->AddPopup("File", filemenu, laymenuitem);
+    AddFrame(menubar, laymenubar);
+    fList->Add(menubar);
+}
+
+void MBrowser::CreateUpperFrame(TGCompositeFrame *frametop)
+{
+
+    //
+    // *********** Create Contents of frame top (upper part) **********
+    //
+    fTop1 = new TGHorizontalFrame(frametop, 300, 100);
+    fTop2 = new TGHorizontalFrame(frametop, 300, 100);
+    fTop3 = new TGHorizontalFrame(frametop, 300, 100);
+
+    frametop->AddFrame(fTop1);
+    frametop->AddFrame(fTop2);
+    frametop->AddFrame(fTop3);
+
+    fList->Add(fTop1);
+    fList->Add(fTop2);
+    fList->Add(fTop3);
+}
+
+void MBrowser::CreateDirListMenu(TGCompositeFrame *frame)
+{
+    //
+    // Create Dir-Listbox and buttons in first frame
+    //
+    fDir = new TGComboBox(frame, M_DIRBOX);
+    fDir->Resize(350, 20);
+
+    fPic1 = fClient->GetPicture("tb_uplevel.xpm");
+    fPic2 = fClient->GetPicture("tb_list.xpm");
+    fPic3 = fClient->GetPicture("tb_details.xpm");
+
+    fCdup     = new TGPictureButton(frame, fPic1, M_PBUTTON_CDIR_UP);
+    fListMode = new TGPictureButton(frame, fPic2, M_PBUTTON_LIST_MODE);
+    fDetail   = new TGPictureButton(frame, fPic3, M_PBUTTON_DETAIL_MODE);
+
+    fCdup    ->SetToolTipText("One Level up!");
+    fListMode->SetToolTipText("List Mode");
+    fDetail  ->SetToolTipText("Details Mode");
+
+    fListMode->SetState(kButtonUp);
+    fDetail  ->SetState(kButtonEngaged);
+
+    fListMode->AllowStayDown(kTRUE);
+    fDetail  ->AllowStayDown(kTRUE);
+
+    fDir     ->Associate(this);
+    fCdup    ->Associate(this);
+    fDetail  ->Associate(this);
+    fListMode->Associate(this);
+
+    fList->Add(fDir);
+    fList->Add(fCdup);
+    fList->Add(fListMode);
+    fList->Add(fDetail);
+
+    //
+    // Layout Dir-Listbox and buttons
+    //
+    TGLayoutHints *laydir = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 5, 5, 5, 5);
+    TGLayoutHints *laybut = new TGLayoutHints(kLHintsLeft|kLHintsTop, 5, 5, 5, 5);
+
+    fList->Add(laydir);
+    fList->Add(laybut);
+
+    frame->AddFrame(fDir,      laydir);
+    frame->AddFrame(fCdup,     laybut);
+    frame->AddFrame(fListMode, laybut);
+    frame->AddFrame(fDetail,   laybut);
+}
+
+void MBrowser::CreateDirListBox(TGCompositeFrame *frame)
+{
+    //
+    // Create file viewer (browser)
+    //
+    fFileView = new TGListView(frame, 540, 380);
+    fList->Add(fFileView);
+
+    TGViewPort *port = fFileView->GetViewPort();
+    port->SetBackgroundColor(fgWhitePixel);
+
+    fFileCont = new TGFileContainer(port, 100, 100, kVerticalFrame, fgWhitePixel);
+    fList->Add(fFileCont);
+
+    fFileView->SetContainer(fFileCont);
+    fFileView->SetViewMode(kLVDetails);
+
+    fFileCont->SetFilter("*");
+    fFileCont->Associate(this);
+    fFileCont->Sort(kSortByName);
+
+    TGLayoutHints *layview = new TGLayoutHints(kLHintsTop|kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
+    fList->Add(layview);
+
+    frame->AddFrame(fFileView, layview);
+}
+
+void MBrowser::CreateTab1(TGCompositeFrame *frame)
+{
+    //
+    // Create three frames for the first tab
+    //
+    TGCompositeFrame *tab1  = new TGCompositeFrame(frame, 100, 100, kHorizontalFrame);
+    TGCompositeFrame *tab1a = new TGCompositeFrame(frame, 100, 100, kHorizontalFrame);
+    TGCompositeFrame *tab1b = new TGCompositeFrame(frame, 100, 100, kVerticalFrame);
+
+    TGLayoutHints *laytab1b = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
+    TGLayoutHints *laytab1  = new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5);
+
+    fList->Add(laytab1b);
+    fList->Add(laytab1);
+
+    frame->AddFrame(tab1a);
+    frame->AddFrame(tab1b, laytab1b);
+    frame->AddFrame(tab1,  laytab1);
+
+    fList->Add(tab1);
+    fList->Add(tab1a);
+    fList->Add(tab1b);
+
+    CreateDirListMenu(tab1a);
+    CreateDirListBox(tab1b);
+}
+
+void MBrowser::CreateLowerFrame(TGCompositeFrame *framelow)
+{
+    //
+    // *********** Create Contents of frame low (downer part) **********
+    //
+
+    //
+    // ----- Create Object holding the Tabs -----
+    //
+    TGTab *tabs = new TGTab(framelow, 400, 400);
+    fList->Add(tabs);
+
+    TGLayoutHints *laytabs = new TGLayoutHints(kLHintsBottom|kLHintsExpandX|kLHintsExpandY, 5, 5, 5, 5);
+    fList->Add(laytabs);
+
+    framelow->AddFrame(tabs, laytabs);
+
+    //
+    // --- Create the first tab of the tabs ---
+    //
+    TGCompositeFrame *tf = tabs->AddTab("Input File");
+
+    CreateTab1(tf);
+}
 
 MBrowser::MBrowser(const TGWindow *main, const TGWindow *p,
@@ -56,123 +229,37 @@
                    main?main:gClient->GetRoot(), w, h)
 {
-
-    //
-    //    Main window to controll the october test
-    //
-
-    //    set non-gui members to starting values
-
     fInputFile[0] = '\0';
 
-    //
-    //    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 ("Close", M_FILE_CLOSE ) ;
-    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 ) ;
-
-    //
-    //    Create the top window with a lot of buttons
-    //
-    fFrameTop = new TGCompositeFrame (this, 300,100, kVerticalFrame ) ;
-
-    fTop1 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
-    fTop2 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
-    fTop3 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
-
-    fFrameTop->AddFrame (fTop1, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
-    fFrameTop->AddFrame (fTop2, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
-    fFrameTop->AddFrame (fTop3, new TGLayoutHints(kLHintsCenterX, 10, 10, 5, 5) );
-    AddFrame(fFrameTop, new TGLayoutHints (kLHintsTop ) ) ;
-
-    //
-    //    Create the low window with a tabs in it
-    //
-    fFrameLow = new TGCompositeFrame (this, 300,100, kHorizontalFrame ) ;
-
-    fLayTab = new TGLayoutHints ( kLHintsExpandX   , 5, 5, 5, 5 ) ;
-
-    //    create the first tab
-
-    fTab = new TGTab ( fFrameLow, 400, 400 ) ;
-
-    TGCompositeFrame *tf = fTab->AddTab("Input File") ;
-
-    fTabF1  = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
-    fTabF1a = new TGCompositeFrame(tf, 100, 100, kHorizontalFrame);
-    fTabF1b = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
-
-    tf->AddFrame(fTabF1a,  new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
-    tf->AddFrame(fTabF1b,  new TGLayoutHints ( kLHintsExpandX | kLHintsExpandY  , 5, 5, 5, 5 ) ) ;
-
-    fDir = new TGComboBox(fTabF1a, M_DIRBOX);
-    fDir->Resize(350, 20) ;
-    fDir->Associate(this);
-
-    fPicCdup   = fClient->GetPicture("tb_uplevel.xpm");
-    fPicList   = fClient->GetPicture("tb_list.xpm");
-    fPicDetail = fClient->GetPicture("tb_details.xpm") ;
-
-    fCdup = new TGPictureButton(fTabF1a, fPicCdup, M_PBUTTON_CDIR_UP ) ;
-    fCdup->SetToolTipText("One Level up!") ;
-    fCdup->Associate(this) ;
-
-    fListMode = new TGPictureButton(fTabF1a, fPicList, M_PBUTTON_LIST_MODE);
-    fListMode->SetToolTipText("List Mode") ;
-    fListMode->Associate(this);
-    fListMode->SetState(kButtonUp);
-    fListMode->AllowStayDown(kTRUE);
-
-    fDetail = new TGPictureButton(fTabF1a, fPicDetail, M_PBUTTON_DETAIL_MODE ) ;
-    fDetail->SetToolTipText("Details Mode") ;
-    fDetail->Associate(this) ;
-    fDetail->SetState(kButtonEngaged) ;
-    fDetail->AllowStayDown(kTRUE) ;
-
-    fTabF1a->AddFrame(fDir,      new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 5, 5, 5, 5)) ;
-    fTabF1a->AddFrame(fCdup,     new TGLayoutHints(kLHintsLeft|kLHintsTop, 5, 5, 5, 5));
-    fTabF1a->AddFrame(fListMode, new TGLayoutHints(kLHintsLeft|kLHintsTop, 5, 5, 5, 5));
-    fTabF1a->AddFrame(fDetail,   new TGLayoutHints(kLHintsLeft|kLHintsTop, 5, 5, 5, 5));
-
-    fFileView = new TGListView(fTabF1b, 540, 380 ) ;
-    fFileCont = new TGFileContainer(fFileView->GetViewPort(), 100, 100,
-                                    kVerticalFrame, fgWhitePixel) ;
-
-    fFileCont->Associate(this) ;
-    fFileView->GetViewPort()->SetBackgroundColor(fgWhitePixel) ;
-    fFileView->SetContainer(fFileCont) ;
-    fFileCont->SetFilter("*") ;
-//    fFileCont->ChangeDirectory(gSystem->WorkingDirectory()) ;
-    fFileView->SetViewMode(kLVDetails);
-    fFileCont->Sort(kSortByName) ;
-
-    fTabF1b->AddFrame(fFileView, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) ) ;
-
-    tf->AddFrame(fTabF1, fLayTab) ;
-
-    fFrameLow->AddFrame ( fTab, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) );
-
-    AddFrame(fFrameLow, new TGLayoutHints (kLHintsExpandX|kLHintsExpandY) ) ;
-
+    fList = new TList;
+    fList->SetOwner();
+
+    CreateMenuBar();
+
+    //
+    // ---- Create the top window with a lot of buttons ----
+    //
+    TGCompositeFrame *frametop = new TGCompositeFrame(this, 300, 100, kVerticalFrame);
+    fList->Add(frametop);
+    AddFrame(frametop);
+
+    //
+    // ---- Create the low window with a tabs in it ----
+    //
+    TGLayoutHints *layframelow = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
+    fList->Add(layframelow);
+
+    TGCompositeFrame *framelow = new TGCompositeFrame(this, 300, 100, kHorizontalFrame);
+    fList->Add(framelow);
+
+    AddFrame(framelow, layframelow);
+
+    CreateUpperFrame(frametop);
+    CreateLowerFrame(framelow);
+
+    //
+    //   Map the window, set up the layout, etc.
+    //
     ChangeDir();
-    //
-    //   Map the window, set up the layout, etc.
-    //
-
-    SetWMSizeHints(400, 350, 1000, 1000, 10, 10 ) ;      // set the smallest and biggest size of the Main frame
+    SetWMSizeHints(400, 350, 1000, 1000, 10, 10);      // set the smallest and biggest size of the Main frame
 }
 
@@ -183,28 +270,10 @@
 MBrowser::~MBrowser()
 {
-  //delete  fPicCdup, fPicList, fPicDetail; 
-    delete fLayTab;
-    delete fLayMenuBar;
-    delete fLayMenuItem;
-    delete fFileView;
-    delete fFileCont;
-    delete fCdup;
-    delete fListMode;
-    delete fDetail;
-    delete fDir ;
-    delete fTabF1b;
-    delete fTabF1a;
-    delete fTabF1;
-    delete fTop3;
-    delete fTop2;
-    delete fTop1;
-    delete fTab;
-    delete fFrameTop;
-    delete fFrameLow;
-    delete fFileMenu;
-    delete fMenuBar;
-
+    fClient->FreePicture(fPic1);
+    fClient->FreePicture(fPic2);
+    fClient->FreePicture(fPic3);
+
+    delete fList;
 } 
-
 
 // ======================================================================
@@ -218,5 +287,5 @@
    // window menu item is selected.
 
-  delete this ; 
+    delete this;
 }
 
@@ -293,11 +362,11 @@
 	    
 	    case M_PBUTTON_LIST_MODE:
-	      fFileView->SetViewMode(kLVList) ; 
+	      fFileView->SetViewMode(kLVList);
               fDetail->SetState(kButtonUp) ;
               return kTRUE;
 	      
           case M_PBUTTON_DETAIL_MODE:
-              fFileView->SetViewMode(kLVDetails) ;
-              fListMode->SetState(kButtonUp) ;
+              fFileView->SetViewMode(kLVDetails);
+              fListMode->SetState(kButtonUp);
               return kTRUE;
           }
@@ -321,5 +390,6 @@
       
   case kC_CONTAINER:
-      switch (GET_SUBMSG(msg)) {
+      switch (GET_SUBMSG(msg))
+      {
 
           //      case kCT_ITEMCLICK:
Index: trunk/MagicSoft/Mars/mmain/MBrowser.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MBrowser.h	(revision 944)
+++ trunk/MagicSoft/Mars/mmain/MBrowser.h	(revision 945)
@@ -19,4 +19,5 @@
 class TGFileContainer;
 class TGListView;
+class TList;
 
 class MBrowser : public TGTransientFrame
@@ -28,42 +29,31 @@
     //
 
-    //   some member not connected with Gui
-
-    //  the things for the menu bar
-
-    TGMenuBar         *fMenuBar ;
-    TGPopupMenu       *fFileMenu ;
-
-    //
-    //   divide the Window in two different parts
-    //
-    TGCompositeFrame  *fFrameTop;   // top part of the main window
-    TGCompositeFrame  *fFrameLow;   // low part of the main window
-    TGTab             *fTab;        // different tabs in the low window
-
     //
     //   the things in the file selector
     //
-    TGCompositeFrame  *fTabF1;     // first tab of low part
-    TGCompositeFrame  *fTabF1a;    // subpart of the file selector in low window
-    TGCompositeFrame  *fTabF1b;    // subpart of the file selector in low window
     TGComboBox        *fDir;
+
     TGPictureButton   *fCdup;
     TGPictureButton   *fListMode;
     TGPictureButton   *fDetail;
+
     TGFileContainer   *fFileCont;
     TGListView        *fFileView;
 
-    //     Layout hints for different uses
 
-    TGLayoutHints     *fLayMenuBar;
-    TGLayoutHints     *fLayMenuItem;
-    TGLayoutHints     *fLayTab;
+    TList             *fList;
 
     //     some icons and pictures often used
 
-    const TGPicture   *fPicCdup;
-    const TGPicture   *fPicList;
-    const TGPicture   *fPicDetail;
+    const TGPicture   *fPic1;
+    const TGPicture   *fPic2;
+    const TGPicture   *fPic3;
+
+    void CreateMenuBar();
+    void CreateUpperFrame(TGCompositeFrame *frameup);
+    void CreateLowerFrame(TGCompositeFrame *framelow);
+    void CreateTab1(TGCompositeFrame *frame);
+    void CreateDirListMenu(TGCompositeFrame *frame);
+    void CreateDirListBox(TGCompositeFrame *frame);
 
 protected:
