Index: trunk/MagicSoft/Mars/mdatacheck/MGDisplayAdc.cc
===================================================================
--- trunk/MagicSoft/Mars/mdatacheck/MGDisplayAdc.cc	(revision 466)
+++ trunk/MagicSoft/Mars/mdatacheck/MGDisplayAdc.cc	(revision 665)
@@ -1,12 +1,8 @@
 #include "MGDisplayAdc.h"
 
-#include <TGListBox.h>           // TGListBox
 #include <TGButton.h>            // TGTextButton
-#include <TGSlider.h>            // TGVSlider
 #include <TCanvas.h>             // TCanvas.h
 #include <TGMsgBox.h>            // TGMsgBox
 #include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
-
-#include "MHistosAdc.h"
 
 enum ComIdentDisplayAdc {
@@ -163,11 +159,10 @@
 	
 	fHistoList->Select(1, kTRUE);
-	fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ;
-	fHistoList->SetTopEntry(fHistoList->GetSelected());
+	DrawSelectedHi() ;
+	SetSelectedTopEntry();
 	fCanv->Modified() ;
-	fCanv->Update() ;
-	fVslider1->SetPosition( fHistoList->GetSelected()-1);
+        fCanv->Update() ;
+        SetSelectedPos();
 	 
-	
 	MapWindow();
 	SetWMSizeHints(550, 550, 1000, 1000, 1, 1); 
@@ -207,6 +202,4 @@
 	delete fFrameLow ; 
 	delete fFrameTop ; 
-	
-	
 }  
 
@@ -233,21 +226,23 @@
 
 Bool_t MGDisplayAdc::BuildHistoList(Int_t type ) 
-{ 
-	//   looks in the container of the AdcSpectra and reads in the 
-	//   Histogramms in there. 
-	//
-	//   In the class MHistosAdc are in fact two lists. One for the high and
-	//   one for the low gain. Here we will use only the high gain list!!!
-	//   With some special options (settings in the gui) we will also be able
-	//   to plot the low gain
-	// 
-	for ( Int_t i=0 ; i < fHists->GetHighEntries(); i++ ) {	       				
-		fHistoList->AddEntry(fHists->GetHighList()->At(i)->GetName(), i+1) ;
-		
-	} 
-	
-	fHistoList->MapSubwindows() ;
-	fHistoList->Layout() ;
-	return (kTRUE) ; 
+{
+    //
+    //   looks in the container of the AdcSpectra and reads in the
+    //   Histogramms in there.
+    //
+    //   In the class MHistosAdc are in fact two lists. One for the high and
+    //   one for the low gain. Here we will use only the high gain list!!!
+    //   With some special options (settings in the gui) we will also be able
+    //   to plot the low gain
+    //
+
+    const Int_t nhi = fHists->GetHiEntries();
+    for ( Int_t i=0 ; i < nhi; i++ ) {
+        fHistoList->AddEntry(fHists->GetHistHi(i)->GetName(), i+1) ;
+    }
+
+    fHistoList->MapSubwindows() ;
+    fHistoList->Layout() ;
+    return kTRUE ;
 } 
 
@@ -257,317 +252,258 @@
 Bool_t MGDisplayAdc::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
 {     
-	
-	// Process events generated by the buttons in the frame.
-	// 
-	Int_t   buttons = 4, retval = 0 ; 
-	//Char_t  wort[100] ;
-	//Char_t  extens[5] ;
-	//Char_t  command[110] ;
-	
-	//TGFileItem *item ;     // to process items in the file view container
-	//void *np = NULL ;      // null pointer
-	
-	switch (GET_MSG(msg)) 
-	{
-	    case kC_COMMAND:
-		switch (GET_SUBMSG(msg)) 
-		{
-		    case kCM_BUTTON:
-			
-			switch (parm1)
-			{  
+    //
+    // Process events generated by the buttons in the frame.
+    //
+    Int_t   buttons = 4, retval = 0 ;
+    //Char_t  wort[100] ;
+    //Char_t  extens[5] ;
+    //Char_t  command[110] ;
+
+    //TGFileItem *item ;     // to process items in the file view container
+    //void *np = NULL ;      // null pointer
+
+    switch (GET_MSG(msg))
+    {
+    case kC_COMMAND:
+        switch (GET_SUBMSG(msg))
+        {
+        case kCM_BUTTON:
+
+            switch (parm1)
+            {
+            case M_BUTTON_SAVE:
+                new TGMsgBox(fClient->GetRoot(), this,
+                             "WARNING!",
+                             "Not implemented yet.",
+                             kMBIconExclamation, buttons, &retval);
+                break ;
+
+            case M_BUTTON_PRINT:
+                break;
+
+            case M_BUTTON_RESET:
+                new TGMsgBox(fClient->GetRoot(), this,
+                             "WARNING!",
+                             "Not implemented yet.",
+                             kMBIconExclamation, buttons, &retval);
+                break;
+
+            case M_BUTTON_CLOSE:
+                CloseWindow() ;
+                break ;
+
+                // The selection for "Next Histogram".
+                // There is also a link for the sicronisation with the slider
+                //
+            case M_BUTTON_PREV:
+                if (GetSelected()-1 != 0)
+                {
+                    if (fHistoLock == kTRUE )
+                    {
+                        fCanvas->cd(1);
+                        SelectSelected();
+                        DrawSelectedHi() ;
+                        fCanvas->cd(2);
+                        DrawSelectedLo() ;
+                    }
+                    else
+                    {
+                        fCanv->cd();
+                        SelectSelected();
+                        DrawSelectedHi() ;
+                    }
+
+                    SetSelectedTopEntry();
+                    fCanv->Modified() ;
+                    fCanv->Update() ;
+                    SetSelectedPos();
+                }
+                if (fRadio[1]->GetState() != kButtonDown)
+                    break;
+
+                fRadio[0]->SetState(kButtonDown);
+                fRadio[1]->SetState(kButtonUp);
+
+                break;
+
+                //The same as above, but for next histogram
+            case M_BUTTON_NEXT:
+                if (GetSelected()-1 != 576)
+                {
+                    if (fHistoLock == kTRUE )
+                    {
+                        fCanvas->cd(1);
+                        SelectSelected();
+                        DrawSelectedHi() ;
+                        fCanvas->cd(2);
+                        DrawSelectedLo() ;
+                    }
+                    else
+                    {
+                        fCanv->cd();
+                        SelectSelected();
+                        DrawSelectedHi() ;
+
+                    }
+                    SetSelectedTopEntry();
+                    fCanv->Modified() ;
+                    fCanv->Update() ;
+                    SetSelectedPos();
+
+                }
+                if (fRadio[1]->GetState() != kButtonDown)
+                    break;
+
+                fRadio[0]->SetState(kButtonDown);
+                fRadio[1]->SetState(kButtonUp);
+
+                break;
+
+            default:
+                break ;
+            }
+            break;
+
+        case kCM_RADIOBUTTON:
+
+            switch(parm1)
+            {
+            case M_RADIO_HIGH:
+                fRadio[1]->SetState(kButtonUp);
+                fRadio[2]->SetState(kButtonUp);
+                fHistoLock = kFALSE;
+                fHistoType=1;
+                fCanv->cd();
+                SelectSelected();
+                DrawSelectedHi() ;
+                SetSelectedTopEntry();
+                fCanv->Modified() ;
+                fCanv->Update() ;
+                SetSelectedPos();
+                break;
 				
-			    case M_BUTTON_SAVE:
-				new TGMsgBox(fClient->GetRoot(), this,
-					     "WARNING!",
-					     "Not implemented yet.",
-					     kMBIconExclamation, buttons, &retval); 
-				
-				break ; 
-				
-			    case M_BUTTON_PRINT:
-				break;
-				
-			    case M_BUTTON_RESET:
-				new TGMsgBox(fClient->GetRoot(), this,
-					     "WARNING!",
-                                             "Not implemented yet.",
-					     kMBIconExclamation, buttons, &retval);  												
-				
-				break;
-				
-				
-			    case M_BUTTON_CLOSE: 
-				CloseWindow() ; 
-				break ; 
-				
-				// The selection for "Next Histogram".
-				// There is also a link for the sicronisation with the slider 
-				// 
-			    case M_BUTTON_PREV:
-								
-				if (!( fHistoList->GetSelected()-1 ) == 0)
-				{
-				    if (fHistoLock == kTRUE )
-				    {
-					    fCanvas->cd(1);
-					    fHistoList->Select(fHistoList->GetSelected()-1, kTRUE); 
-					    fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ;
-					    fCanvas->cd(2);
-					    fHists->GetLowList()->At( fHistoList->GetSelected()-1)->Draw() ; 
-				    }
-					else
-					{
-						fCanv->cd();
-						fHistoList->Select(fHistoList->GetSelected()-1, kTRUE);
-						fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ; 
-					}
-					
-					fHistoList->SetTopEntry(fHistoList->GetSelected());  
-					fCanv->Modified() ;
-					fCanv->Update() ;
-					fVslider1->SetPosition( fHistoList->GetSelected()-1);
-				}
-				if ((fRadio[1]->GetState()) == kButtonDown)
-				{
-					fRadio[0]->SetState(kButtonDown);
-					fRadio[1]->SetState(kButtonUp);
-				} 
-				
-
-				break;
-				
-				//The same as above, but for next histogram
-				
-			    case M_BUTTON_NEXT:
-			        
-				if (!((fHistoList->GetSelected()-1)==576))
-					
-                                {
-					if (fHistoLock == kTRUE )
-					{
-						fCanvas->cd(1);
-						fHistoList->Select(fHistoList->GetSelected()+1, kTRUE);
-						fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ;
-						fCanvas->cd(2);
-						fHists->GetLowList()->At( fHistoList->GetSelected()-1)->Draw() ;  
-					}										
-					else
-                                        {  
-						fCanv->cd();
-                                                fHistoList->Select(fHistoList->GetSelected()+1, kTRUE);
-                                                fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ; 
-						
-					}
-						fHistoList->SetTopEntry(fHistoList->GetSelected());
-						fCanv->Modified() ;
-						fCanv->Update() ;
-						fVslider1->SetPosition( fHistoList->GetSelected()-1);
-					
-				}
-				if ((fRadio[1]->GetState()) == kButtonDown)
-					{
-						fRadio[0]->SetState(kButtonDown);
-						fRadio[1]->SetState(kButtonUp);
-					}
-				break;
-			    default:
-				break ;
-			} 
-			
-		    case kCM_MENU:
-			switch (parm1)
-			{
-			}
-			break ;
-			
-		    default:
-			break ;
+            case M_RADIO_LOW:
+                fRadio[0]->SetState(kButtonUp);
+                fRadio[2]->SetState(kButtonUp);
+                fCanv->cd();
+                fHistoLock = kFALSE;
+                fHistoType = 2;
+
+                SelectSelected();
+                DrawSelectedLo() ;
+                SetSelectedTopEntry();
+
+                fCanv->Modified() ;
+                fCanv->Update() ;
+                SetSelectedPos();
+                break;
+
+            case M_RADIO_LH:
+                fRadio[0]->SetState(kButtonUp);
+                fRadio[1]->SetState(kButtonUp);
+
+                if (fHistoLock == kFALSE)
+                {
+                    fCanvas = fECanv->GetCanvas();
+                    fCanvas->Divide(1,2, 0, 0 ,0);
+
+                    fCanv->Modified() ;
+                    fCanv->Update() ;
+                    fHistoLock = kTRUE;
+                    fHistoType = 3;
+                }
+
+                fCanvas->cd(1);
+
+                SelectSelected();
+                DrawSelectedHi() ;
+                SetSelectedTopEntry();
+
+                fCanvas->cd(2);
+                SelectSelected();
+                DrawSelectedLo() ;
+                SetSelectedTopEntry();
+
+                fCanv->Modified() ;
+                fCanv->Update();
+
+            default:
+                break;
+            }
+            break;
+        }
 		
-		
-			
-		    case kCM_RADIOBUTTON:
-	  
-			switch(parm1)
-			{
-			    case M_RADIO_HIGH:
-				fRadio[1]->SetState(kButtonUp);
-				fRadio[2]->SetState(kButtonUp);
-				fHistoLock = kFALSE;
-				fHistoType=1;
-                                fCanv->cd();
-				fHistoList->Select(fHistoList->GetSelected(), kTRUE);
-                                fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ;
-                                fHistoList->SetTopEntry(fHistoList->GetSelected());
-                                fCanv->Modified() ;
-                                fCanv->Update() ;
-                                fVslider1->SetPosition( fHistoList->GetSelected()-1);
-				
-				
-				break;
-				
-			    case M_RADIO_LOW:
-				fRadio[0]->SetState(kButtonUp);
-				fRadio[2]->SetState(kButtonUp);
-				fCanv->cd(); 
-				fHistoLock = kFALSE;
-				fHistoType = 2;
-				
-				fHistoList->Select(fHistoList->GetSelected(), kTRUE);
-				fHists->GetLowList()->At( fHistoList->GetSelected()-1)->Draw() ;
-				fHistoList->SetTopEntry(fHistoList->GetSelected());
-				
-				fCanv->Modified() ;
-				fCanv->Update() ;
-				fVslider1->SetPosition( fHistoList->GetSelected()-1);
-				
-				break;
-			    case M_RADIO_LH:
-				fRadio[0]->SetState(kButtonUp);
-                                fRadio[1]->SetState(kButtonUp); 
-				
-				if (fHistoLock == kFALSE)
-				{
-					fCanvas = fECanv->GetCanvas(); 
-					fCanvas->Divide(1,2, 0, 0 ,0);
-
-					fCanv->Modified() ;
-					fCanv->Update() ;  
-					fHistoLock = kTRUE;
-					fHistoType = 3; 
-				
-				}
-			       
-				fCanvas->cd(1);
- 
-				fHistoList->Select(fHistoList->GetSelected(), kTRUE);
-                                fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ;
-                                fHistoList->SetTopEntry(fHistoList->GetSelected());
-				
-				
-				
-				
-				fCanvas->cd(2);
-                                fHistoList->Select(fHistoList->GetSelected(), kTRUE);
-                                fHists->GetLowList()->At( fHistoList->GetSelected()-1)->Draw() ;
-                                fHistoList->SetTopEntry(fHistoList->GetSelected());     
-				
-				
-				
-                                fCanv->Modified() ;
-                                fCanv->Update();
-				
-			    default:
-				break;
-			}
-			break;
-		   
-			
-		}
-		
-	    case kCM_LISTBOX:
-	      switch  (GET_SUBMSG(msg)) 
-		{
-		    case M_LIST_HISTO: 
-			
-			if (fHistoLock == kTRUE ) 
-			{
-				fCanvas->cd(1);
-				fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ;
-				fCanvas->cd(2);
-				fHists->GetLowList()->At( fHistoList->GetSelected()-1)->Draw() ; 				
-				
-			}
-			else
-			{
-			
-				fCanv->cd() ; 
-			
-				fHists->GetHighList()->At( fHistoList->GetSelected()-1)->Draw() ; 
-			
-			}
-			fCanv->Modified() ; 
-			fCanv->Update() ;
-			fVslider1->SetPosition( fHistoList->GetSelected()-1);
-		  
-		  
-		  
-		default:
-		  break ;
-		}
-	      
-		
-	case kC_CONTAINER: 
-	  switch (GET_SUBMSG(msg)) 
-	    {
-	      
-	    case kCT_ITEMDBLCLICK: 
-	      
-	      break; 
-			
-	    default:
-	      break ;
-	    }
-	  
-	  
-	  
-	default:
-	  break;
-	  
-	case kC_VSLIDER:
-	  switch(GET_SUBMSG(msg))
-	    {
-	    case kSL_POS:
-	      {
-		switch(parm1)
-		  {
-		      case M_VSId1:
-
-			  // Check for the slider movement and sicronise with TGListBox		    
-			  if ((parm2 >= 0) && (parm2) <= 576)
-			  {
-				  
-				  if (fHistoLock==kTRUE)
-				  {
-					  fCanvas->cd(1) ;
-					  fHists->GetHighList()->At(parm2)->Draw() ;
-					  fHistoList->Select(parm2+1, kTRUE);
-					 
-					  fCanvas->cd(2) ; 
-					  fHists->GetLowList()->At(parm2)->Draw() ;
-                                          fHistoList->Select(parm2+1, kTRUE);
-					  fHistoList->SetTopEntry(fHistoList->GetSelected()); 
-					  
-				  }
-				  
-				  else 
-				  {
-					  fCanv->cd() ;  
-					  fHists->GetHighList()->At(parm2)->Draw() ;
-					  fHistoList->Select(parm2+1, kTRUE); 
-					  
-					  fHistoList->SetTopEntry(fHistoList->GetSelected());
-					  
-				  }
-					  fCanv->Modified() ;
-					  fCanv->Update() ;
-				  
-				  if ((fRadio[1]->GetState()) == kButtonDown)
-				  {
-					  fRadio[0]->SetState(kButtonDown);
-					  fRadio[1]->SetState(kButtonUp);
-				  }   
-				  
-				  
-			  }
-		    break;
-		  }
-		break;				
-	      }					
-	      break;
-	    }
-	  break;
-	  
-	}
-	return kTRUE;
-} 
+    case kCM_LISTBOX:
+        if (GET_SUBMSG(msg) != M_LIST_HISTO)
+            break;
+
+        if (fHistoLock == kTRUE )
+        {
+            fCanvas->cd(1);
+            DrawSelectedHi() ;
+            fCanvas->cd(2);
+            DrawSelectedLo() ;
+        }
+        else
+        {
+            fCanv->cd() ;
+            DrawSelectedHi() ;
+        }
+        fCanv->Modified() ;
+        fCanv->Update() ;
+        SetSelectedPos();
+        break ;
+
+/*
+    case kC_CONTAINER:
+        switch (GET_SUBMSG(msg))
+        {
+
+        case kCT_ITEMDBLCLICK:
+            break;
+
+        default:
+            break ;
+        }
+*/
+
+    case kC_VSLIDER:
+        if (GET_SUBMSG(msg)!=kSL_POS || parm1!=M_VSId1)
+            break;
+
+        // Check for the slider movement and sicronise with TGListBox
+        if (parm2<0 || parm2>576)
+            break;
+
+        if (fHistoLock==kTRUE)
+        {
+            fCanvas->cd(1) ;
+            DrawHi(parm2) ;
+            fHistoList->Select(parm2+1, kTRUE);
+
+            fCanvas->cd(2) ;
+            DrawLo(parm2) ;
+        }
+        else
+        {
+            fCanv->cd() ;
+            DrawHi(parm2) ;
+        }
+
+        fHistoList->Select(parm2+1, kTRUE);
+        SetSelectedTopEntry();
+
+        fCanv->Modified() ;
+        fCanv->Update() ;
+
+        if (fRadio[1]->GetState() != kButtonDown)
+            break;
+
+        fRadio[0]->SetState(kButtonDown);
+        fRadio[1]->SetState(kButtonUp);
+
+        break;
+
+    }
+    return kTRUE;
+}
