// @(#)root/graf:$Id$
// Author: Matthew.Adam.Dobbs   06/09/99

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include <stdio.h>

#include "TStyle.h"
#include "TLatex.h"
#include "TLine.h"
#include "TBox.h"
#include "TMarker.h"
#include "TLegend.h"
#include "TList.h"
#include "TVirtualPad.h"
#include "TMath.h"
#include "TROOT.h"
#include "TLegendEntry.h"
#include "Riostream.h"
#include "TMultiGraph.h"
#include "THStack.h"


ClassImp(TLegend)


//______________________________________________________________________________
/* Begin_Html
<center><h2>Legend class</h2></center>
This class displays a legend box (TPaveText) containing several legend entries.
Each legend entry is made of a reference to a ROOT object, a text label and an
option specifying which graphical attributes (marker/line/fill) should be
displayed.
<p>
The following example shows how to create a legend. In this example the legend
contains a histogram, a function and a graph. The histogram is put in the legend
using its reference pointer whereas the graph and the function are added
using their names. Note that, because <tt>TGraph</tt> constructors do not have the
<tt>TGraph</tt> name as parameter, the graph name should be specified using the
<tt>SetName</tt> method.
<p>
When an object is added by name, a scan is performed on the list of objects
contained in the current pad (<tt>gPad</tt>) and also in the possible
<tt>TMultiGraph</tt> and <tt>THStack</tt> present in the pad. If a matching
name is found, the corresponding object is added in the legend using its pointer.

End_Html
Begin_Macro(source)
{
   TCanvas *c1 = new TCanvas("c1","c1",600,500);
   gStyle->SetOptStat(0);

   TH1F *h1 = new TH1F("h1","TLegend Example",200,-10,10);
   h1->FillRandom("gaus",30000);
   h1->SetFillColor(kGreen);
   h1->SetFillStyle(3003);
   h1->Draw();

   TF1 *f1=new TF1("f1","1000*TMath::Abs(sin(x)/x)",-10,10);
   f1->SetLineColor(kBlue);
   f1->SetLineWidth(4);
   f1->Draw("same");

   const Int_t n = 20;
   Double_t x[n], y[n], ex[n], ey[n];
   for (Int_t i=0;i<n;i++) {
      x[i]  = i*0.1;
      y[i]  = 1000*sin(x[i]+0.2);
      x[i]  = 17.8*x[i]-8.9;
      ex[i] = 1.0;
      ey[i] = 10.*i;
   }
   TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey);
   gr->SetName("gr");
   gr->SetLineColor(kRed);
   gr->SetLineWidth(2);
   gr->SetMarkerStyle(21);
   gr->SetMarkerSize(1.3);
   gr->SetMarkerColor(7);
   gr->Draw("P");

   leg = new TLegend(0.1,0.7,0.48,0.9);
   leg->SetHeader("The Legend Title");
   leg->AddEntry(h1,"Histogram filled with random numbers","f");
   leg->AddEntry("f1","Function abs(#frac{sin(x)}{x})","l");
   leg->AddEntry("gr","Graph with error bars","lep");
   leg->Draw();

   return c1;
}
End_Macro
Begin_Html
<br>
<tt>TLegend</tt> inherits from <tt>TAttText</tt> therefore changing any
text attributes (text alignment, font, color...) on a legend will changed the
text attributes on each line.
<br>
In particular it can be interesting to change the text alignement that way. In
order to have a base-line vertical alignment instead of a centered one simply do:
<pre>
   leg->SetTextAlign(13);
</pre
or
<pre>
   leg->SetTextAlign(11);
</pre
The default value of some <tt>TLegend</tt> attributes can be changed using
<tt>gStyle</tt>. The default settings are:
<pre>
   SetLegendBorderSize(1);
   SetLegendFillColor(0);
   SetLegendFont(42);
   SetLegendTextSize(0.);
<pre>
The global attributes change the default values for the next created legends.
<p>
Text attributes can be also changed individually on each legend entry:
<pre>
   TLegendEntry *le = leg->AddEntry(h1,"Histogram filled with random numbers","f");
   le->SetTextColor(kBlue);;
</pre>
<br>
Note that the <tt>TPad</tt> class has a method to build automatically a legend
for all objects in the pad. It is called <tt>TPad::BuildLegend()</tt>.
<p>
Each item in the legend is added using the <tt>AddEntry</tt> method. This
method defines the object to be added (by reference or name), the label
associated to this object and an option which a combination of:
<ul>
<li> L: draw line associated with TAttLine if obj inherits from TAttLine
<li> P: draw polymarker associated with TAttMarker if obj inherits from TAttMarker
<li> F: draw a box with fill associated wit TAttFill if obj inherits TAttFill
<li> E: draw vertical error bar
</ul>
<p>
As shown in the following example, passing a NULL pointer as first parameter in
<tt>AddEntry</tt> is also valid. This allows to add text or blank lines in a
legend.

End_Html
Begin_Macro(source)
{
   TCanvas *c2 = new TCanvas("c2","c2",500,300);

   TLegend* leg = new TLegend(0.2, 0.2, .8, .8);
   TH1* h = new TH1F("", "", 1, 0, 1);

   leg->AddEntry(h, "Histogram \"h\"", "l");
   leg->AddEntry((TObject*)0, "", "");
   leg->AddEntry((TObject*)0, "Some text", "");
   leg->AddEntry((TObject*)0, "", "");
   leg->AddEntry(h, "Histogram \"h\" again", "l");

   leg->Draw();
   return c2;
}
End_Macro
Begin_Html
<br>
It is possible to draw the legend entries over several columns using
the method <tt>SetNColumns()</tt> like in the following example.

End_Html
Begin_Macro(source)
{
   TCanvas *c3 = new TCanvas("c2","c2",500,300);

   TLegend* leg = new TLegend(0.2, 0.2, .8, .8);
   TH1* h = new TH1F("", "", 1, 0, 1);

   leg-> SetNColumns(2);

   leg->AddEntry(h, "Column 1 line 1", "l");
   leg->AddEntry(h, "Column 2 line 1", "l");
   leg->AddEntry(h, "Column 1 line 2", "l");
   leg->AddEntry(h, "Column 2 line 2", "l");

   leg->Draw();
   return c3;
}
End_Macro
*/


//______________________________________________________________________________
TLegend::TLegend(): TPave(), TAttText(12,0,1,gStyle->GetLegendFont(),0)
{
   /* Begin_Html
   Default constructor.
   End_Html */

   fPrimitives = 0;
   SetDefaults();
   SetBorderSize(gStyle->GetLegendBorderSize());
   SetFillColor(gStyle->GetLegendFillColor());
}


//______________________________________________________________________________
TLegend::TLegend( Double_t x1, Double_t y1,Double_t x2, Double_t y2,
                  const char *header, Option_t *option)
        :TPave(x1,y1,x2,y2,4,option), TAttText(12,0,1,gStyle->GetLegendFont(),0)
{
   /* Begin_Html
   Normal constructor.
   <p>
   A TLegend is a Pave with several TLegendEntry(s).
   x1,y1,x2,y2 are the coordinates of the Legend in the current pad
   (in normalised coordinates by default)
   "header" is the title that will be displayed at the top of the legend
   it is treated like a regular entry and supports TLatex. The default
   is no header (header = 0).
   The options are the same as for TPave Default = "brNDC"
   End_Html */

   fPrimitives = new TList;
   if ( header && strlen(header) > 0) {
      TLegendEntry *headerEntry = new TLegendEntry( 0, header, "h" );
      headerEntry->SetTextAlign(0);
      headerEntry->SetTextAngle(0);
      headerEntry->SetTextColor(0);
      headerEntry->SetTextFont(gStyle->GetLegendFont());
      headerEntry->SetTextSize(0);
      fPrimitives->AddFirst(headerEntry);
   }
   SetDefaults();
   SetBorderSize(gStyle->GetLegendBorderSize());
   SetFillColor(gStyle->GetLegendFillColor());
}


//______________________________________________________________________________
TLegend::TLegend( const TLegend &legend ) : TPave(legend), TAttText(legend),
                                            fPrimitives(0)
{
   /* Begin_Html
   Copy constructor.
   End_Html */

  if (legend.fPrimitives) {
      fPrimitives = new TList();
      TListIter it(legend.fPrimitives);
      while (TLegendEntry *e = (TLegendEntry *)it.Next()) {
         TLegendEntry *newentry = new TLegendEntry(*e);
         fPrimitives->Add(newentry);
      }
   }
   ((TLegend&)legend).Copy(*this);
}


//______________________________________________________________________________
TLegend& TLegend::operator=(const TLegend &lg)
{
   /* Begin_Html
   Assignment operator.
   End_Html */

   if(this!=&lg) {
      TPave::operator=(lg);
      TAttText::operator=(lg);
      fPrimitives=lg.fPrimitives;
      fEntrySeparation=lg.fEntrySeparation;
      fMargin=lg.fMargin;
      fNColumns=lg.fNColumns;
   }
   return *this;
}


//______________________________________________________________________________
TLegend::~TLegend()
{
   /* Begin_Html
   Default destructor.
   End_Html */

   if (fPrimitives) fPrimitives->Delete();
   delete fPrimitives;
   fPrimitives = 0;
}


//______________________________________________________________________________
TLegendEntry *TLegend::AddEntry(const TObject *obj, const char *label, Option_t *option)
{
   /* Begin_Html
   Add a new entry to this legend. "obj" is the object to be represented.
   "label" is the text you wish to associate with obj in the legend.
   If "label" is null or empty, the title of the object will be used.
   <p>
   Options are:
   <ul>
   <li> L: draw line associated with TAttLine if obj inherits from TAttLine
   <li> P: draw polymarker associated with TAttMarker if obj inherits from TAttMarker
   <li> F: draw a box with fill associated wit TAttFill if obj inherits TAttFill
   <li> E: draw vertical error bar if option "L" is also specified
   </ul>
   End_Html */

   const char *lab = label;

   if (obj && (!label || strlen(label)==0)) lab = obj->GetTitle();
   TLegendEntry *newentry = new TLegendEntry( obj, lab, option );
   if ( !fPrimitives ) fPrimitives = new TList;
   fPrimitives->Add(newentry);
   return newentry;
}


//______________________________________________________________________________
TLegendEntry *TLegend::AddEntry(const char *name, const char *label, Option_t *option)
{
   /* Begin_Html
   Add a new entry to this legend. "name" is the name of an object in the pad to
   be represented label is the text you wish to associate with obj in the legend
   if label is null or empty, the title of the object will be used.
   <p>
   Options are:
   <ul>
   <li> L: draw line associated with TAttLine if obj inherits from TAttLine
   <li> P: draw polymarker associated with TAttMarker if obj inherits from TAttMarker
   <li> F: draw a box with fill associated wit TAttFill if obj inherits TAttFill
   <li> E: draw vertical error bar if option "L" is also specified
   </ul>
   End_Html */

   if (!gPad) {
      Error("AddEntry", "need to create a canvas first");
      return 0;
   }

   TObject *obj = gPad->FindObject(name);

   // If the object "name" has not been found, the following code tries to
   // find it in TMultiGraph or THStack possibly present in the current pad.
   if (!obj) {
      TList *lop = gPad->GetListOfPrimitives();
      if (lop) {
         TObject *o=0;
         TIter next(lop);
         while( (o=next()) ) {
            if ( o->InheritsFrom(TMultiGraph::Class() ) ) {
               TList * grlist = ((TMultiGraph *)o)->GetListOfGraphs();
               obj = grlist->FindObject(name);
               if (obj) break;
            }
            if ( o->InheritsFrom(THStack::Class() ) ) {
               TList * hlist = ((THStack *)o)->GetHists();
               obj = hlist->FindObject(name);
               if (obj) break;
            }
         }
      }
   }

   return AddEntry( obj, label, option );
}


//______________________________________________________________________________
void TLegend::Clear( Option_t *)
{
   /* Begin_Html
   Clear all entries in this legend, including the header.
   End_Html */

   if (!fPrimitives) return;
   fPrimitives->Delete();
}


//______________________________________________________________________________
void TLegend::Copy( TObject &obj ) const
{
   /* Begin_Html
   Copy this legend into "obj".
   End_Html */

   TPave::Copy(obj);
   TAttText::Copy((TLegend&)obj);
   ((TLegend&)obj).fEntrySeparation = fEntrySeparation;
   ((TLegend&)obj).fMargin = fMargin;
   ((TLegend&)obj).fNColumns = fNColumns;
}


//______________________________________________________________________________
void TLegend::DeleteEntry()
{
   /* Begin_Html
   Delete entry at the mouse position.
   End_Html */

   if ( !fPrimitives ) return;
   TLegendEntry* entry = GetEntry();   // get entry pointed by the mouse
   if ( !entry ) return;
   fPrimitives->Remove(entry);
   delete entry;
}


//______________________________________________________________________________
void TLegend::Draw( Option_t *option )
{
   /* Begin_Html
   Draw this legend with its current attributes.
   End_Html */

   AppendPad(option);
}


//______________________________________________________________________________
void TLegend::EditEntryAttFill()
{
   /* Begin_Html
   Edit the fill attributes for the entry pointed by the mouse.
   End_Html */

   TLegendEntry* entry = GetEntry();   // get entry pointed by the mouse
   if ( !entry ) return;
   gROOT->SetSelectedPrimitive( entry );
   entry->SetFillAttributes();
}


//______________________________________________________________________________
void TLegend::EditEntryAttLine()
{
   /* Begin_Html
   Edit the line attributes for the entry pointed by the mouse.
   End_Html */

   TLegendEntry* entry = GetEntry();   // get entry pointed by the mouse
   if ( !entry ) return;
   gROOT->SetSelectedPrimitive( entry );
   entry->SetLineAttributes();
}


//______________________________________________________________________________
void TLegend::EditEntryAttMarker()
{
   /* Begin_Html
   Edit the marker attributes for the entry pointed by the mouse.
   End_Html */

   TLegendEntry* entry = GetEntry();   // get entry pointed by the mouse
   if ( !entry ) return;
   gROOT->SetSelectedPrimitive( entry );
   entry->SetMarkerAttributes();
}


//______________________________________________________________________________
void TLegend::EditEntryAttText()
{
   /* Begin_Html
   Edit the text attributes for the entry pointed by the mouse.
   End_Html */

   TLegendEntry* entry = GetEntry();   // get entry pointed by the mouse
   if ( !entry ) return;
   gROOT->SetSelectedPrimitive( entry );
   entry->SetTextAttributes();
}


//______________________________________________________________________________
TLegendEntry *TLegend::GetEntry() const
{
   /* Begin_Html
   Get entry pointed to by the mouse.
   This method is mostly a tool for other methods inside this class.
   End_Html */

   if (!gPad) {
      Error("GetEntry", "need to create a canvas first");
      return 0;
   }

   Int_t nRows = GetNRows();
   if ( nRows == 0 ) return 0;

   Double_t ymouse = gPad->AbsPixeltoY(gPad->GetEventY())-fY1;
   Double_t yspace = (fY2 - fY1)/nRows;

   Int_t nColumns = GetNColumns();
   Double_t xmouse = gPad->AbsPixeltoX(gPad->GetEventX())-fX1;
   Double_t xspace = 0.;
   if (nColumns > 0) xspace = (fX2 - fX1)/nColumns;

   Int_t ix = 1;
   if (xspace > 0.) ix = (Int_t)(xmouse/xspace)+1;
   if (ix > nColumns) ix = nColumns;
   if (ix < 1)        ix = 1;

   Int_t iy = nRows-(Int_t)(ymouse/yspace);
   if (iy > nRows) iy = nRows;
   if (iy < 1)     iy = 1;

   Int_t nloops = TMath::Min(ix+(nColumns*(iy-1)), fPrimitives->GetSize());

   TIter next(fPrimitives);
   TLegendEntry *entry = 0;

   for (Int_t i=1; i<= nloops; i++) entry = (TLegendEntry *)next();

   return entry;
}


//______________________________________________________________________________
const char *TLegend::GetHeader() const
{
   /* Begin_Html
   Returns the header, which is the title that appears at the top
   of the legend.
   End_Html */

   if ( !fPrimitives ) return 0;
      TIter next(fPrimitives);
   TLegendEntry *first;   // header is always the first entry
   if ((  first = (TLegendEntry*)next()  )) {
      TString opt = first->GetOption();
      opt.ToLower();
      if ( opt.Contains("h") ) return first->GetLabel();
   }
   return 0;
}


//______________________________________________________________________________
void TLegend::InsertEntry( const char* objectName, const char* label, Option_t* option)
{
   /* Begin_Html
   Add a new entry before the entry at the mouse position.
   End_Html */

   if (!gPad) {
      Error("InsertEntry", "need to create a canvas first");
      return;
   }

   TLegendEntry* beforeEntry = GetEntry();   // get entry pointed by the mouse
   TObject *obj = gPad->FindObject( objectName );

   // note either obj OR beforeEntry may be zero at this point

   TLegendEntry *newentry = new TLegendEntry( obj, label, option );

   if ( !fPrimitives ) fPrimitives = new TList;
   if ( beforeEntry ) {
      fPrimitives->AddBefore( (TObject*)beforeEntry, (TObject*)newentry );
   } else {
      fPrimitives->Add((TObject*)newentry);
   }
}


//______________________________________________________________________________
void TLegend::Paint( Option_t* option )
{
   /* Begin_Html
   Paint this legend with its current attributes.
   End_Html */

   TPave::ConvertNDCtoPad();
   TPave::PaintPave(fX1,fY1,fX2,fY2,GetBorderSize(),option);
   PaintPrimitives();
}


//______________________________________________________________________________
Int_t TLegend::GetNRows() const
{
   /* Begin_Html
   Get the number of rows.
   End_Html */

   Int_t nEntries = 0;
   if ( fPrimitives ) nEntries = fPrimitives->GetSize();
   if ( nEntries == 0 ) return 0;

   Int_t nRows;
   if(GetHeader() != NULL) nRows = 1 + (Int_t) TMath::Ceil((Double_t) (nEntries-1)/fNColumns);
   else  nRows = (Int_t) TMath::Ceil((Double_t) nEntries/fNColumns);

   return nRows;
}


//______________________________________________________________________________
void TLegend::SetNColumns(Int_t nColumns)
{
   /* Begin_Html
   Set the number of columns for the legend. The header, if set, is given
   its own row. After that, every nColumns entries are inserted into the
   same row. For example, if one calls legend.SetNColumns(2), and there
   is no header, then the first two TObjects added to the legend will be
   in the first row, the next two will appear in the second row, and so on.
   End_Html */

   if(nColumns < 1) {
      Warning("TLegend::SetNColumns", "illegal value nColumns = %d; keeping fNColumns = %d", nColumns, fNColumns);
      return;
   }
   fNColumns = nColumns;
}


//______________________________________________________________________________
void TLegend::PaintPrimitives()
{
   /* Begin_Html
   Paint the entries (list of primitives) for this legend.
   End_Html */

   Int_t nRows = GetNRows();
   if ( nRows == 0 ) return;

   // Evaluate text size as a function of the number of entries
   //  taking into account their real size after drawing latex
   // Note: in pixel coords y1 > y2=0, but x2 > x1=0
   //       in NDC          y2 > y1,   and x2 > x1

   Double_t x1 = fX1NDC;
   Double_t y1 = fY1NDC;
   Double_t x2 = fX2NDC;
   Double_t y2 = fY2NDC;
   Double_t margin = fMargin*( x2-x1 )/fNColumns;
   Double_t boxwidth = margin;
   Double_t boxw = boxwidth*0.35;
   Double_t yspace = (y2-y1)/nRows;
   Double_t yspace2 = yspace/2.;
   Double_t textsize = GetTextSize();
   Double_t save_textsize = textsize;
   if (textsize==0.) {
      SetTextSize(gStyle->GetLegendTextSize());
      textsize = GetTextSize();
   }
   Bool_t autosize = kFALSE;
   Double_t* columnWidths = new Double_t[fNColumns];
   memset(columnWidths, 0, fNColumns*sizeof(Double_t));

   if ( textsize == 0 ) {
      autosize = kTRUE;
      textsize = ( 1. - fEntrySeparation ) * yspace;

      // find the max width and height (in pad coords) of one latex entry label
      Double_t maxentrywidth = 0, maxentryheight = 0;
      TIter nextsize(fPrimitives);
      TLegendEntry *entrysize;
      Int_t iColumn = 0;
      while (( entrysize = (TLegendEntry *)nextsize() )) {
         TLatex entrytex( 0, 0, entrysize->GetLabel() );
         entrytex.SetNDC();
         Style_t tfont = entrysize->GetTextFont();
         if (tfont == 0) tfont = GetTextFont();
         if (tfont%10 == 3) --tfont;
         entrytex.SetTextFont(tfont);
         entrytex.SetTextSize(textsize);
         if ( entrytex.GetYsize() > maxentryheight ) {
            maxentryheight = entrytex.GetYsize();
         }
         TString opt = entrysize->GetOption();
         opt.ToLower();
         if ( opt.Contains("h") ) {
            if ( entrytex.GetXsize() > maxentrywidth ) {
               maxentrywidth = entrytex.GetXsize();
            }
         } else {
            if ( entrytex.GetXsize() > columnWidths[iColumn] ) {
               columnWidths[iColumn] = entrytex.GetXsize();
            }
            iColumn++;
            iColumn %= fNColumns;
         }
         Double_t tmpMaxWidth = 0.0;
         for(int i=0; i<fNColumns; i++) tmpMaxWidth += columnWidths[i];
         if ( tmpMaxWidth > maxentrywidth) maxentrywidth = tmpMaxWidth;
      }
      // make sure all labels fit in the allotted space
      Double_t tmpsize_h = maxentryheight /(gPad->GetY2() - gPad->GetY1());
      textsize = TMath::Min( textsize, tmpsize_h );
      Double_t tmpsize_w = textsize*(fX2-fX1)*(1.0-fMargin)/maxentrywidth;
      if(fNColumns > 1) tmpsize_w = textsize*(fX2-fX1)*(1.0-fMargin-fColumnSeparation)/maxentrywidth;
      textsize = TMath::Min( textsize, tmpsize_w );
      SetTextSize( textsize );
   }

   // Update column widths, put into NDC units
   // block off this section of code to make sure all variables are local:
   // don't want to ruin initialisation of these variables later on
   {
      TIter next(fPrimitives);
      TLegendEntry *entry;
      Int_t iColumn = 0;
      memset(columnWidths, 0, fNColumns*sizeof(Double_t));
      while (( entry = (TLegendEntry *)next() )) {
         TLatex entrytex( 0, 0, entry->GetLabel() );
         entrytex.SetNDC();
         Style_t tfont = entry->GetTextFont();
         if (tfont == 0) tfont = GetTextFont();
         if (autosize && tfont%10 == 3) --tfont;
         entrytex.SetTextFont(tfont);
         if(entry->GetTextSize() == 0) entrytex.SetTextSize(textsize);
         TString opt = entry->GetOption();
         opt.ToLower();
         if (!opt.Contains("h")) {
            if ( entrytex.GetXsize() > columnWidths[iColumn] ) {
               columnWidths[iColumn] = entrytex.GetXsize();
            }
            iColumn++;
            iColumn %= fNColumns;
         }
      }
      double totalWidth = 0.0;
      for(int i=0; i<fNColumns; i++) totalWidth += columnWidths[i];
      if(fNColumns > 1) totalWidth /= (1.0-fMargin-fColumnSeparation);
      else totalWidth /= (1.0 - fMargin);
      for(int i=0; i<fNColumns; i++) {
         columnWidths[i] = columnWidths[i]/totalWidth*(x2-x1) + margin;
      }
   }

   Double_t ytext = y2 + 0.5*yspace;  // y-location of 0th entry

   // iterate over and paint all the TLegendEntries
   TIter next(fPrimitives);
   TLegendEntry *entry;
   Int_t iColumn = 0;
   while (( entry = (TLegendEntry *)next() )) {
      if(iColumn == 0) ytext -= yspace;

      // Draw Label in Latexmargin

      Short_t talign = entry->GetTextAlign();
      Float_t tangle = entry->GetTextAngle();
      Color_t tcolor = entry->GetTextColor();
      Style_t tfont  = entry->GetTextFont();
      Size_t  tsize  = entry->GetTextSize();
      // if the user hasn't set a parameter, then set it to the TLegend value
      if (talign == 0) entry->SetTextAlign(GetTextAlign());
      if (tangle == 0) entry->SetTextAngle(GetTextAngle());
      if (tcolor == 0) entry->SetTextColor(GetTextColor());
      if (tfont  == 0) {
         tfont = GetTextFont();
         if (autosize && tfont%10 == 3) --tfont;
         entry->SetTextFont(tfont);
      }
      if (tsize  == 0) entry->SetTextSize(GetTextSize());
      // set x,y according to the requested alignment
      Double_t x=0,y=0;
      Int_t halign = entry->GetTextAlign()/10;
      Double_t entrymargin = margin;
      // for the header the margin is near zero
      TString opt = entry->GetOption();
      opt.ToLower();
      x1 = fX1NDC;
      x2 = fX2NDC;
      if ( opt.Contains("h") ) entrymargin = margin/10.;
      else if (fNColumns > 1) {
         for(int i=0; i<iColumn; i++) x1 += columnWidths[i] + fColumnSeparation*(fX2NDC-fX1NDC)/(fNColumns-1);
         x2 = x1 + columnWidths[iColumn];
         iColumn++;
         iColumn %= fNColumns;
      }
      if (halign == 1) x = x1 + entrymargin;
      if (halign == 2) x = 0.5*( (x1+entrymargin) + x2 );
      if (halign == 3) x = x2 - entrymargin/10.;
      Int_t valign = entry->GetTextAlign()%10;

      if (valign == 1) y = ytext - (1. - fEntrySeparation)* yspace2;
      if (valign == 3) y = ytext + (1. - fEntrySeparation)* yspace2;

      // The vertical alignment "centered" is treated in a special way
      // to ensure a better spacing between lines.
      if (valign == 2) {
         Float_t tsizepad = textsize;
         if (tfont%10 == 3) tsizepad = (gPad->AbsPixeltoY(0) - gPad->AbsPixeltoY(textsize))/(gPad->GetY2() - gPad->GetY1());
         if (yspace2 < tsizepad) {
            entry->SetTextAlign(10*halign+1);
            y = ytext - (1. - fEntrySeparation)* yspace2/2.;
         } else {
            y = ytext;
         }
      }

      TLatex entrytex( x, y, entry->GetLabel() );
      entrytex.SetNDC();
      entry->TAttText::Copy(entrytex);
      entrytex.Paint();

      // reset attributes back to their original values
      entry->SetTextAlign(talign);
      entry->SetTextAngle(tangle);
      entry->SetTextColor(tcolor);
      entry->SetTextFont(tfont);
      entry->SetTextSize(tsize);

      // define x,y as the center of the symbol for this entry
      Double_t xsym = x1 + margin/2.;
      Double_t ysym = ytext;

      TObject *eobj = entry->GetObject();

      // Draw fill pattern (in a box)

      if ( opt.Contains("f")) {
         if (eobj && eobj->InheritsFrom(TAttFill::Class())) {
            dynamic_cast<TAttFill*>(eobj)->Copy(*entry);
         }

         // box total height is yspace*0.7
         entry->TAttFill::Modify();
         Double_t xf[4],yf[4];
         xf[0] = xsym - boxw;
         yf[0] = ysym - yspace*0.35;
         xf[1] = xsym + boxw;
         yf[1] = yf[0];
         xf[2] = xf[1];
         yf[2] = ysym + yspace*0.35;
         xf[3] = xf[0];
         yf[3] = yf[2];
         for (Int_t i=0;i<4;i++) {
            xf[i] = gPad->GetX1() + xf[i]*(gPad->GetX2()-gPad->GetX1());
            yf[i] = gPad->GetY1() + yf[i]*(gPad->GetY2()-gPad->GetY1());
         }
         gPad->PaintFillArea(4,xf,yf);
      }

      // Draw line

      if ( opt.Contains("l") || opt.Contains("f")) {

         if (eobj && eobj->InheritsFrom(TAttLine::Class())) {
            dynamic_cast<TAttLine*>(eobj)->Copy(*entry);
         }
         // line total length (in x) is margin*0.8
         TLine entryline( xsym - boxw, ysym, xsym + boxw, ysym );
         entryline.SetBit(TLine::kLineNDC);
         entry->TAttLine::Copy(entryline);
         // if the entry is filled, then surround the box with the line instead
         if ( opt.Contains("f") && !opt.Contains("l")) {
            // box total height is yspace*0.7
            boxwidth = yspace*
               (gPad->GetX2()-gPad->GetX1())/(gPad->GetY2()-gPad->GetY1());
            if ( boxwidth > margin ) boxwidth = margin;

            entryline.PaintLineNDC( xsym - boxw, ysym + yspace*0.35,
                                 xsym + boxw, ysym + yspace*0.35);
            entryline.PaintLineNDC( xsym - boxw, ysym - yspace*0.35,
                                 xsym + boxw, ysym - yspace*0.35);
            entryline.PaintLineNDC( xsym + boxw, ysym - yspace*0.35,
                                 xsym + boxw, ysym + yspace*0.35);
            entryline.PaintLineNDC( xsym - boxw, ysym - yspace*0.35,
                                 xsym - boxw, ysym + yspace*0.35);
         } else {
            entryline.Paint();
            if (opt.Contains("e")) {
               entryline.PaintLineNDC( xsym, ysym - yspace*0.30,
                                       xsym, ysym + yspace*0.30);
            }
         }
      }

      // Draw error only

      if (opt.Contains("e") && !(opt.Contains("l") || opt.Contains("f"))) {
         if (eobj && eobj->InheritsFrom(TAttLine::Class())) {
            dynamic_cast<TAttLine*>(eobj)->Copy(*entry);
         }
         TLine entryline(xsym, ysym - yspace*0.30,
                         xsym, ysym + yspace*0.30);
         entryline.SetBit(TLine::kLineNDC);
         entry->TAttLine::Copy(entryline);
         entryline.Paint();
      }

      // Draw Polymarker

      if ( opt.Contains("p")) {

         if (eobj && eobj->InheritsFrom(TAttMarker::Class())) {
            dynamic_cast<TAttMarker*>(eobj)->Copy(*entry);
         }
         TMarker entrymarker( xsym, ysym, 0 );
         entrymarker.SetNDC();
         entry->TAttMarker::Copy(entrymarker);
         entrymarker.Paint();
      }
   }

   SetTextSize(save_textsize);
   delete [] columnWidths;
}


//______________________________________________________________________________
void TLegend::Print( Option_t* option ) const
{
   /* Begin_Html
   Dump this TLegend and its contents.
   End_Html */

   TPave::Print( option );
   if (fPrimitives) fPrimitives->Print();
}


//______________________________________________________________________________
void TLegend::RecursiveRemove(TObject *obj)
{
   /* Begin_Html
   Reset the legend entries pointing to "obj".
   End_Html */

   TIter next(fPrimitives);
   TLegendEntry *entry;
   while (( entry = (TLegendEntry *)next() )) {
      if (entry->GetObject() == obj) entry->SetObject((TObject*)0);
   }
}


//______________________________________________________________________________
void TLegend::SavePrimitive(std::ostream &out, Option_t* )
{
   /* Begin_Html
   Save this legend as C++ statements on output stream out
   to be used with the SaveAs .C option.
   End_Html */

   out << "   " << std::endl;
   char quote = '"';
   if ( gROOT->ClassSaved( TLegend::Class() ) ) {
      out << "   ";
   } else {
      out << "   TLegend *";
   }
   // note, we can always use NULL header, since its included in primitives
   out << "leg = new TLegend("<<GetX1NDC()<<","<<GetY1NDC()<<","
       <<GetX2NDC()<<","<<GetY2NDC()<<","
       << "NULL" << "," <<quote<< fOption <<quote<<");" << std::endl;
   if (fBorderSize != 4) {
      out<<"   leg->SetBorderSize("<<fBorderSize<<");"<<std::endl;
   }
   SaveTextAttributes(out,"leg",12,0,1,42,0);
   SaveLineAttributes(out,"leg",-1,-1,-1);
   SaveFillAttributes(out,"leg",-1,-1);
   if ( fPrimitives ) {
      TIter next(fPrimitives);
      TLegendEntry *entry;
      while (( entry = (TLegendEntry *)next() )) entry->SaveEntry(out,"leg");
   }
   out << "   leg->Draw();"<<std::endl;
}


//______________________________________________________________________________
void TLegend::SetEntryLabel( const char* label )
{
   /* Begin_Html
   Edit the label of the entry pointed to by the mouse.
   End_Html */

   TLegendEntry* entry = GetEntry();   // get entry pointed by the mouse
   if ( entry ) entry->SetLabel( label );
}


//______________________________________________________________________________
void TLegend::SetEntryOption( Option_t* option )
{
   /* Begin_Html
   Edit the option of the entry pointed to by the mouse.
   End_Html */

   TLegendEntry* entry = GetEntry();   // get entry pointed by the mouse
   if ( entry ) entry->SetOption( option );
}


//______________________________________________________________________________
void TLegend::SetHeader( const char *header )
{
   /* Begin_Html
   Sets the header, which is the "title" that appears at the top of the legend.
   End_Html */

   if ( !fPrimitives ) fPrimitives = new TList;
   TIter next(fPrimitives);
   TLegendEntry *first;   // header is always the first entry
   if ((  first = (TLegendEntry*)next() )) {
      TString opt = first->GetOption();
      opt.ToLower();
      if ( opt.Contains("h") ) {
         first->SetLabel(header);
         return;
      }
   }
   first = new TLegendEntry( 0, header, "h" );
   first->SetTextAlign(0);
   first->SetTextAngle(0);
   first->SetTextColor(0);
   first->SetTextFont(GetTextFont()); // default font is TLegend font for the header
   first->SetTextSize(0);
   fPrimitives->AddFirst((TObject*)first);
}
 TLegend.cxx:1
 TLegend.cxx:2
 TLegend.cxx:3
 TLegend.cxx:4
 TLegend.cxx:5
 TLegend.cxx:6
 TLegend.cxx:7
 TLegend.cxx:8
 TLegend.cxx:9
 TLegend.cxx:10
 TLegend.cxx:11
 TLegend.cxx:12
 TLegend.cxx:13
 TLegend.cxx:14
 TLegend.cxx:15
 TLegend.cxx:16
 TLegend.cxx:17
 TLegend.cxx:18
 TLegend.cxx:19
 TLegend.cxx:20
 TLegend.cxx:21
 TLegend.cxx:22
 TLegend.cxx:23
 TLegend.cxx:24
 TLegend.cxx:25
 TLegend.cxx:26
 TLegend.cxx:27
 TLegend.cxx:28
 TLegend.cxx:29
 TLegend.cxx:30
 TLegend.cxx:31
 TLegend.cxx:32
 TLegend.cxx:33
 TLegend.cxx:34
 TLegend.cxx:35
 TLegend.cxx:36
 TLegend.cxx:37
 TLegend.cxx:38
 TLegend.cxx:39
 TLegend.cxx:40
 TLegend.cxx:41
 TLegend.cxx:42
 TLegend.cxx:43
 TLegend.cxx:44
 TLegend.cxx:45
 TLegend.cxx:46
 TLegend.cxx:47
 TLegend.cxx:48
 TLegend.cxx:49
 TLegend.cxx:50
 TLegend.cxx:51
 TLegend.cxx:52
 TLegend.cxx:53
 TLegend.cxx:54
 TLegend.cxx:55
 TLegend.cxx:56
 TLegend.cxx:57
 TLegend.cxx:58
 TLegend.cxx:59
 TLegend.cxx:60
 TLegend.cxx:61
 TLegend.cxx:62
 TLegend.cxx:63
 TLegend.cxx:64
 TLegend.cxx:65
 TLegend.cxx:66
 TLegend.cxx:67
 TLegend.cxx:68
 TLegend.cxx:69
 TLegend.cxx:70
 TLegend.cxx:71
 TLegend.cxx:72
 TLegend.cxx:73
 TLegend.cxx:74
 TLegend.cxx:75
 TLegend.cxx:76
 TLegend.cxx:77
 TLegend.cxx:78
 TLegend.cxx:79
 TLegend.cxx:80
 TLegend.cxx:81
 TLegend.cxx:82
 TLegend.cxx:83
 TLegend.cxx:84
 TLegend.cxx:85
 TLegend.cxx:86
 TLegend.cxx:87
 TLegend.cxx:88
 TLegend.cxx:89
 TLegend.cxx:90
 TLegend.cxx:91
 TLegend.cxx:92
 TLegend.cxx:93
 TLegend.cxx:94
 TLegend.cxx:95
 TLegend.cxx:96
 TLegend.cxx:97
 TLegend.cxx:98
 TLegend.cxx:99
 TLegend.cxx:100
 TLegend.cxx:101
 TLegend.cxx:102
 TLegend.cxx:103
 TLegend.cxx:104
 TLegend.cxx:105
 TLegend.cxx:106
 TLegend.cxx:107
 TLegend.cxx:108
 TLegend.cxx:109
 TLegend.cxx:110
 TLegend.cxx:111
 TLegend.cxx:112
 TLegend.cxx:113
 TLegend.cxx:114
 TLegend.cxx:115
 TLegend.cxx:116
 TLegend.cxx:117
 TLegend.cxx:118
 TLegend.cxx:119
 TLegend.cxx:120
 TLegend.cxx:121
 TLegend.cxx:122
 TLegend.cxx:123
 TLegend.cxx:124
 TLegend.cxx:125
 TLegend.cxx:126
 TLegend.cxx:127
 TLegend.cxx:128
 TLegend.cxx:129
 TLegend.cxx:130
 TLegend.cxx:131
 TLegend.cxx:132
 TLegend.cxx:133
 TLegend.cxx:134
 TLegend.cxx:135
 TLegend.cxx:136
 TLegend.cxx:137
 TLegend.cxx:138
 TLegend.cxx:139
 TLegend.cxx:140
 TLegend.cxx:141
 TLegend.cxx:142
 TLegend.cxx:143
 TLegend.cxx:144
 TLegend.cxx:145
 TLegend.cxx:146
 TLegend.cxx:147
 TLegend.cxx:148
 TLegend.cxx:149
 TLegend.cxx:150
 TLegend.cxx:151
 TLegend.cxx:152
 TLegend.cxx:153
 TLegend.cxx:154
 TLegend.cxx:155
 TLegend.cxx:156
 TLegend.cxx:157
 TLegend.cxx:158
 TLegend.cxx:159
 TLegend.cxx:160
 TLegend.cxx:161
 TLegend.cxx:162
 TLegend.cxx:163
 TLegend.cxx:164
 TLegend.cxx:165
 TLegend.cxx:166
 TLegend.cxx:167
 TLegend.cxx:168
 TLegend.cxx:169
 TLegend.cxx:170
 TLegend.cxx:171
 TLegend.cxx:172
 TLegend.cxx:173
 TLegend.cxx:174
 TLegend.cxx:175
 TLegend.cxx:176
 TLegend.cxx:177
 TLegend.cxx:178
 TLegend.cxx:179
 TLegend.cxx:180
 TLegend.cxx:181
 TLegend.cxx:182
 TLegend.cxx:183
 TLegend.cxx:184
 TLegend.cxx:185
 TLegend.cxx:186
 TLegend.cxx:187
 TLegend.cxx:188
 TLegend.cxx:189
 TLegend.cxx:190
 TLegend.cxx:191
 TLegend.cxx:192
 TLegend.cxx:193
 TLegend.cxx:194
 TLegend.cxx:195
 TLegend.cxx:196
 TLegend.cxx:197
 TLegend.cxx:198
 TLegend.cxx:199
 TLegend.cxx:200
 TLegend.cxx:201
 TLegend.cxx:202
 TLegend.cxx:203
 TLegend.cxx:204
 TLegend.cxx:205
 TLegend.cxx:206
 TLegend.cxx:207
 TLegend.cxx:208
 TLegend.cxx:209
 TLegend.cxx:210
 TLegend.cxx:211
 TLegend.cxx:212
 TLegend.cxx:213
 TLegend.cxx:214
 TLegend.cxx:215
 TLegend.cxx:216
 TLegend.cxx:217
 TLegend.cxx:218
 TLegend.cxx:219
 TLegend.cxx:220
 TLegend.cxx:221
 TLegend.cxx:222
 TLegend.cxx:223
 TLegend.cxx:224
 TLegend.cxx:225
 TLegend.cxx:226
 TLegend.cxx:227
 TLegend.cxx:228
 TLegend.cxx:229
 TLegend.cxx:230
 TLegend.cxx:231
 TLegend.cxx:232
 TLegend.cxx:233
 TLegend.cxx:234
 TLegend.cxx:235
 TLegend.cxx:236
 TLegend.cxx:237
 TLegend.cxx:238
 TLegend.cxx:239
 TLegend.cxx:240
 TLegend.cxx:241
 TLegend.cxx:242
 TLegend.cxx:243
 TLegend.cxx:244
 TLegend.cxx:245
 TLegend.cxx:246
 TLegend.cxx:247
 TLegend.cxx:248
 TLegend.cxx:249
 TLegend.cxx:250
 TLegend.cxx:251
 TLegend.cxx:252
 TLegend.cxx:253
 TLegend.cxx:254
 TLegend.cxx:255
 TLegend.cxx:256
 TLegend.cxx:257
 TLegend.cxx:258
 TLegend.cxx:259
 TLegend.cxx:260
 TLegend.cxx:261
 TLegend.cxx:262
 TLegend.cxx:263
 TLegend.cxx:264
 TLegend.cxx:265
 TLegend.cxx:266
 TLegend.cxx:267
 TLegend.cxx:268
 TLegend.cxx:269
 TLegend.cxx:270
 TLegend.cxx:271
 TLegend.cxx:272
 TLegend.cxx:273
 TLegend.cxx:274
 TLegend.cxx:275
 TLegend.cxx:276
 TLegend.cxx:277
 TLegend.cxx:278
 TLegend.cxx:279
 TLegend.cxx:280
 TLegend.cxx:281
 TLegend.cxx:282
 TLegend.cxx:283
 TLegend.cxx:284
 TLegend.cxx:285
 TLegend.cxx:286
 TLegend.cxx:287
 TLegend.cxx:288
 TLegend.cxx:289
 TLegend.cxx:290
 TLegend.cxx:291
 TLegend.cxx:292
 TLegend.cxx:293
 TLegend.cxx:294
 TLegend.cxx:295
 TLegend.cxx:296
 TLegend.cxx:297
 TLegend.cxx:298
 TLegend.cxx:299
 TLegend.cxx:300
 TLegend.cxx:301
 TLegend.cxx:302
 TLegend.cxx:303
 TLegend.cxx:304
 TLegend.cxx:305
 TLegend.cxx:306
 TLegend.cxx:307
 TLegend.cxx:308
 TLegend.cxx:309
 TLegend.cxx:310
 TLegend.cxx:311
 TLegend.cxx:312
 TLegend.cxx:313
 TLegend.cxx:314
 TLegend.cxx:315
 TLegend.cxx:316
 TLegend.cxx:317
 TLegend.cxx:318
 TLegend.cxx:319
 TLegend.cxx:320
 TLegend.cxx:321
 TLegend.cxx:322
 TLegend.cxx:323
 TLegend.cxx:324
 TLegend.cxx:325
 TLegend.cxx:326
 TLegend.cxx:327
 TLegend.cxx:328
 TLegend.cxx:329
 TLegend.cxx:330
 TLegend.cxx:331
 TLegend.cxx:332
 TLegend.cxx:333
 TLegend.cxx:334
 TLegend.cxx:335
 TLegend.cxx:336
 TLegend.cxx:337
 TLegend.cxx:338
 TLegend.cxx:339
 TLegend.cxx:340
 TLegend.cxx:341
 TLegend.cxx:342
 TLegend.cxx:343
 TLegend.cxx:344
 TLegend.cxx:345
 TLegend.cxx:346
 TLegend.cxx:347
 TLegend.cxx:348
 TLegend.cxx:349
 TLegend.cxx:350
 TLegend.cxx:351
 TLegend.cxx:352
 TLegend.cxx:353
 TLegend.cxx:354
 TLegend.cxx:355
 TLegend.cxx:356
 TLegend.cxx:357
 TLegend.cxx:358
 TLegend.cxx:359
 TLegend.cxx:360
 TLegend.cxx:361
 TLegend.cxx:362
 TLegend.cxx:363
 TLegend.cxx:364
 TLegend.cxx:365
 TLegend.cxx:366
 TLegend.cxx:367
 TLegend.cxx:368
 TLegend.cxx:369
 TLegend.cxx:370
 TLegend.cxx:371
 TLegend.cxx:372
 TLegend.cxx:373
 TLegend.cxx:374
 TLegend.cxx:375
 TLegend.cxx:376
 TLegend.cxx:377
 TLegend.cxx:378
 TLegend.cxx:379
 TLegend.cxx:380
 TLegend.cxx:381
 TLegend.cxx:382
 TLegend.cxx:383
 TLegend.cxx:384
 TLegend.cxx:385
 TLegend.cxx:386
 TLegend.cxx:387
 TLegend.cxx:388
 TLegend.cxx:389
 TLegend.cxx:390
 TLegend.cxx:391
 TLegend.cxx:392
 TLegend.cxx:393
 TLegend.cxx:394
 TLegend.cxx:395
 TLegend.cxx:396
 TLegend.cxx:397
 TLegend.cxx:398
 TLegend.cxx:399
 TLegend.cxx:400
 TLegend.cxx:401
 TLegend.cxx:402
 TLegend.cxx:403
 TLegend.cxx:404
 TLegend.cxx:405
 TLegend.cxx:406
 TLegend.cxx:407
 TLegend.cxx:408
 TLegend.cxx:409
 TLegend.cxx:410
 TLegend.cxx:411
 TLegend.cxx:412
 TLegend.cxx:413
 TLegend.cxx:414
 TLegend.cxx:415
 TLegend.cxx:416
 TLegend.cxx:417
 TLegend.cxx:418
 TLegend.cxx:419
 TLegend.cxx:420
 TLegend.cxx:421
 TLegend.cxx:422
 TLegend.cxx:423
 TLegend.cxx:424
 TLegend.cxx:425
 TLegend.cxx:426
 TLegend.cxx:427
 TLegend.cxx:428
 TLegend.cxx:429
 TLegend.cxx:430
 TLegend.cxx:431
 TLegend.cxx:432
 TLegend.cxx:433
 TLegend.cxx:434
 TLegend.cxx:435
 TLegend.cxx:436
 TLegend.cxx:437
 TLegend.cxx:438
 TLegend.cxx:439
 TLegend.cxx:440
 TLegend.cxx:441
 TLegend.cxx:442
 TLegend.cxx:443
 TLegend.cxx:444
 TLegend.cxx:445
 TLegend.cxx:446
 TLegend.cxx:447
 TLegend.cxx:448
 TLegend.cxx:449
 TLegend.cxx:450
 TLegend.cxx:451
 TLegend.cxx:452
 TLegend.cxx:453
 TLegend.cxx:454
 TLegend.cxx:455
 TLegend.cxx:456
 TLegend.cxx:457
 TLegend.cxx:458
 TLegend.cxx:459
 TLegend.cxx:460
 TLegend.cxx:461
 TLegend.cxx:462
 TLegend.cxx:463
 TLegend.cxx:464
 TLegend.cxx:465
 TLegend.cxx:466
 TLegend.cxx:467
 TLegend.cxx:468
 TLegend.cxx:469
 TLegend.cxx:470
 TLegend.cxx:471
 TLegend.cxx:472
 TLegend.cxx:473
 TLegend.cxx:474
 TLegend.cxx:475
 TLegend.cxx:476
 TLegend.cxx:477
 TLegend.cxx:478
 TLegend.cxx:479
 TLegend.cxx:480
 TLegend.cxx:481
 TLegend.cxx:482
 TLegend.cxx:483
 TLegend.cxx:484
 TLegend.cxx:485
 TLegend.cxx:486
 TLegend.cxx:487
 TLegend.cxx:488
 TLegend.cxx:489
 TLegend.cxx:490
 TLegend.cxx:491
 TLegend.cxx:492
 TLegend.cxx:493
 TLegend.cxx:494
 TLegend.cxx:495
 TLegend.cxx:496
 TLegend.cxx:497
 TLegend.cxx:498
 TLegend.cxx:499
 TLegend.cxx:500
 TLegend.cxx:501
 TLegend.cxx:502
 TLegend.cxx:503
 TLegend.cxx:504
 TLegend.cxx:505
 TLegend.cxx:506
 TLegend.cxx:507
 TLegend.cxx:508
 TLegend.cxx:509
 TLegend.cxx:510
 TLegend.cxx:511
 TLegend.cxx:512
 TLegend.cxx:513
 TLegend.cxx:514
 TLegend.cxx:515
 TLegend.cxx:516
 TLegend.cxx:517
 TLegend.cxx:518
 TLegend.cxx:519
 TLegend.cxx:520
 TLegend.cxx:521
 TLegend.cxx:522
 TLegend.cxx:523
 TLegend.cxx:524
 TLegend.cxx:525
 TLegend.cxx:526
 TLegend.cxx:527
 TLegend.cxx:528
 TLegend.cxx:529
 TLegend.cxx:530
 TLegend.cxx:531
 TLegend.cxx:532
 TLegend.cxx:533
 TLegend.cxx:534
 TLegend.cxx:535
 TLegend.cxx:536
 TLegend.cxx:537
 TLegend.cxx:538
 TLegend.cxx:539
 TLegend.cxx:540
 TLegend.cxx:541
 TLegend.cxx:542
 TLegend.cxx:543
 TLegend.cxx:544
 TLegend.cxx:545
 TLegend.cxx:546
 TLegend.cxx:547
 TLegend.cxx:548
 TLegend.cxx:549
 TLegend.cxx:550
 TLegend.cxx:551
 TLegend.cxx:552
 TLegend.cxx:553
 TLegend.cxx:554
 TLegend.cxx:555
 TLegend.cxx:556
 TLegend.cxx:557
 TLegend.cxx:558
 TLegend.cxx:559
 TLegend.cxx:560
 TLegend.cxx:561
 TLegend.cxx:562
 TLegend.cxx:563
 TLegend.cxx:564
 TLegend.cxx:565
 TLegend.cxx:566
 TLegend.cxx:567
 TLegend.cxx:568
 TLegend.cxx:569
 TLegend.cxx:570
 TLegend.cxx:571
 TLegend.cxx:572
 TLegend.cxx:573
 TLegend.cxx:574
 TLegend.cxx:575
 TLegend.cxx:576
 TLegend.cxx:577
 TLegend.cxx:578
 TLegend.cxx:579
 TLegend.cxx:580
 TLegend.cxx:581
 TLegend.cxx:582
 TLegend.cxx:583
 TLegend.cxx:584
 TLegend.cxx:585
 TLegend.cxx:586
 TLegend.cxx:587
 TLegend.cxx:588
 TLegend.cxx:589
 TLegend.cxx:590
 TLegend.cxx:591
 TLegend.cxx:592
 TLegend.cxx:593
 TLegend.cxx:594
 TLegend.cxx:595
 TLegend.cxx:596
 TLegend.cxx:597
 TLegend.cxx:598
 TLegend.cxx:599
 TLegend.cxx:600
 TLegend.cxx:601
 TLegend.cxx:602
 TLegend.cxx:603
 TLegend.cxx:604
 TLegend.cxx:605
 TLegend.cxx:606
 TLegend.cxx:607
 TLegend.cxx:608
 TLegend.cxx:609
 TLegend.cxx:610
 TLegend.cxx:611
 TLegend.cxx:612
 TLegend.cxx:613
 TLegend.cxx:614
 TLegend.cxx:615
 TLegend.cxx:616
 TLegend.cxx:617
 TLegend.cxx:618
 TLegend.cxx:619
 TLegend.cxx:620
 TLegend.cxx:621
 TLegend.cxx:622
 TLegend.cxx:623
 TLegend.cxx:624
 TLegend.cxx:625
 TLegend.cxx:626
 TLegend.cxx:627
 TLegend.cxx:628
 TLegend.cxx:629
 TLegend.cxx:630
 TLegend.cxx:631
 TLegend.cxx:632
 TLegend.cxx:633
 TLegend.cxx:634
 TLegend.cxx:635
 TLegend.cxx:636
 TLegend.cxx:637
 TLegend.cxx:638
 TLegend.cxx:639
 TLegend.cxx:640
 TLegend.cxx:641
 TLegend.cxx:642
 TLegend.cxx:643
 TLegend.cxx:644
 TLegend.cxx:645
 TLegend.cxx:646
 TLegend.cxx:647
 TLegend.cxx:648
 TLegend.cxx:649
 TLegend.cxx:650
 TLegend.cxx:651
 TLegend.cxx:652
 TLegend.cxx:653
 TLegend.cxx:654
 TLegend.cxx:655
 TLegend.cxx:656
 TLegend.cxx:657
 TLegend.cxx:658
 TLegend.cxx:659
 TLegend.cxx:660
 TLegend.cxx:661
 TLegend.cxx:662
 TLegend.cxx:663
 TLegend.cxx:664
 TLegend.cxx:665
 TLegend.cxx:666
 TLegend.cxx:667
 TLegend.cxx:668
 TLegend.cxx:669
 TLegend.cxx:670
 TLegend.cxx:671
 TLegend.cxx:672
 TLegend.cxx:673
 TLegend.cxx:674
 TLegend.cxx:675
 TLegend.cxx:676
 TLegend.cxx:677
 TLegend.cxx:678
 TLegend.cxx:679
 TLegend.cxx:680
 TLegend.cxx:681
 TLegend.cxx:682
 TLegend.cxx:683
 TLegend.cxx:684
 TLegend.cxx:685
 TLegend.cxx:686
 TLegend.cxx:687
 TLegend.cxx:688
 TLegend.cxx:689
 TLegend.cxx:690
 TLegend.cxx:691
 TLegend.cxx:692
 TLegend.cxx:693
 TLegend.cxx:694
 TLegend.cxx:695
 TLegend.cxx:696
 TLegend.cxx:697
 TLegend.cxx:698
 TLegend.cxx:699
 TLegend.cxx:700
 TLegend.cxx:701
 TLegend.cxx:702
 TLegend.cxx:703
 TLegend.cxx:704
 TLegend.cxx:705
 TLegend.cxx:706
 TLegend.cxx:707
 TLegend.cxx:708
 TLegend.cxx:709
 TLegend.cxx:710
 TLegend.cxx:711
 TLegend.cxx:712
 TLegend.cxx:713
 TLegend.cxx:714
 TLegend.cxx:715
 TLegend.cxx:716
 TLegend.cxx:717
 TLegend.cxx:718
 TLegend.cxx:719
 TLegend.cxx:720
 TLegend.cxx:721
 TLegend.cxx:722
 TLegend.cxx:723
 TLegend.cxx:724
 TLegend.cxx:725
 TLegend.cxx:726
 TLegend.cxx:727
 TLegend.cxx:728
 TLegend.cxx:729
 TLegend.cxx:730
 TLegend.cxx:731
 TLegend.cxx:732
 TLegend.cxx:733
 TLegend.cxx:734
 TLegend.cxx:735
 TLegend.cxx:736
 TLegend.cxx:737
 TLegend.cxx:738
 TLegend.cxx:739
 TLegend.cxx:740
 TLegend.cxx:741
 TLegend.cxx:742
 TLegend.cxx:743
 TLegend.cxx:744
 TLegend.cxx:745
 TLegend.cxx:746
 TLegend.cxx:747
 TLegend.cxx:748
 TLegend.cxx:749
 TLegend.cxx:750
 TLegend.cxx:751
 TLegend.cxx:752
 TLegend.cxx:753
 TLegend.cxx:754
 TLegend.cxx:755
 TLegend.cxx:756
 TLegend.cxx:757
 TLegend.cxx:758
 TLegend.cxx:759
 TLegend.cxx:760
 TLegend.cxx:761
 TLegend.cxx:762
 TLegend.cxx:763
 TLegend.cxx:764
 TLegend.cxx:765
 TLegend.cxx:766
 TLegend.cxx:767
 TLegend.cxx:768
 TLegend.cxx:769
 TLegend.cxx:770
 TLegend.cxx:771
 TLegend.cxx:772
 TLegend.cxx:773
 TLegend.cxx:774
 TLegend.cxx:775
 TLegend.cxx:776
 TLegend.cxx:777
 TLegend.cxx:778
 TLegend.cxx:779
 TLegend.cxx:780
 TLegend.cxx:781
 TLegend.cxx:782
 TLegend.cxx:783
 TLegend.cxx:784
 TLegend.cxx:785
 TLegend.cxx:786
 TLegend.cxx:787
 TLegend.cxx:788
 TLegend.cxx:789
 TLegend.cxx:790
 TLegend.cxx:791
 TLegend.cxx:792
 TLegend.cxx:793
 TLegend.cxx:794
 TLegend.cxx:795
 TLegend.cxx:796
 TLegend.cxx:797
 TLegend.cxx:798
 TLegend.cxx:799
 TLegend.cxx:800
 TLegend.cxx:801
 TLegend.cxx:802
 TLegend.cxx:803
 TLegend.cxx:804
 TLegend.cxx:805
 TLegend.cxx:806
 TLegend.cxx:807
 TLegend.cxx:808
 TLegend.cxx:809
 TLegend.cxx:810
 TLegend.cxx:811
 TLegend.cxx:812
 TLegend.cxx:813
 TLegend.cxx:814
 TLegend.cxx:815
 TLegend.cxx:816
 TLegend.cxx:817
 TLegend.cxx:818
 TLegend.cxx:819
 TLegend.cxx:820
 TLegend.cxx:821
 TLegend.cxx:822
 TLegend.cxx:823
 TLegend.cxx:824
 TLegend.cxx:825
 TLegend.cxx:826
 TLegend.cxx:827
 TLegend.cxx:828
 TLegend.cxx:829
 TLegend.cxx:830
 TLegend.cxx:831
 TLegend.cxx:832
 TLegend.cxx:833
 TLegend.cxx:834
 TLegend.cxx:835
 TLegend.cxx:836
 TLegend.cxx:837
 TLegend.cxx:838
 TLegend.cxx:839
 TLegend.cxx:840
 TLegend.cxx:841
 TLegend.cxx:842
 TLegend.cxx:843
 TLegend.cxx:844
 TLegend.cxx:845
 TLegend.cxx:846
 TLegend.cxx:847
 TLegend.cxx:848
 TLegend.cxx:849
 TLegend.cxx:850
 TLegend.cxx:851
 TLegend.cxx:852
 TLegend.cxx:853
 TLegend.cxx:854
 TLegend.cxx:855
 TLegend.cxx:856
 TLegend.cxx:857
 TLegend.cxx:858
 TLegend.cxx:859
 TLegend.cxx:860
 TLegend.cxx:861
 TLegend.cxx:862
 TLegend.cxx:863
 TLegend.cxx:864
 TLegend.cxx:865
 TLegend.cxx:866
 TLegend.cxx:867
 TLegend.cxx:868
 TLegend.cxx:869
 TLegend.cxx:870
 TLegend.cxx:871
 TLegend.cxx:872
 TLegend.cxx:873
 TLegend.cxx:874
 TLegend.cxx:875
 TLegend.cxx:876
 TLegend.cxx:877
 TLegend.cxx:878
 TLegend.cxx:879
 TLegend.cxx:880
 TLegend.cxx:881
 TLegend.cxx:882
 TLegend.cxx:883
 TLegend.cxx:884
 TLegend.cxx:885
 TLegend.cxx:886
 TLegend.cxx:887
 TLegend.cxx:888
 TLegend.cxx:889
 TLegend.cxx:890
 TLegend.cxx:891
 TLegend.cxx:892
 TLegend.cxx:893
 TLegend.cxx:894
 TLegend.cxx:895
 TLegend.cxx:896
 TLegend.cxx:897
 TLegend.cxx:898
 TLegend.cxx:899
 TLegend.cxx:900
 TLegend.cxx:901
 TLegend.cxx:902
 TLegend.cxx:903
 TLegend.cxx:904
 TLegend.cxx:905
 TLegend.cxx:906
 TLegend.cxx:907
 TLegend.cxx:908
 TLegend.cxx:909
 TLegend.cxx:910
 TLegend.cxx:911
 TLegend.cxx:912
 TLegend.cxx:913
 TLegend.cxx:914
 TLegend.cxx:915
 TLegend.cxx:916
 TLegend.cxx:917
 TLegend.cxx:918
 TLegend.cxx:919
 TLegend.cxx:920
 TLegend.cxx:921
 TLegend.cxx:922
 TLegend.cxx:923
 TLegend.cxx:924
 TLegend.cxx:925
 TLegend.cxx:926
 TLegend.cxx:927
 TLegend.cxx:928
 TLegend.cxx:929
 TLegend.cxx:930
 TLegend.cxx:931
 TLegend.cxx:932
 TLegend.cxx:933
 TLegend.cxx:934
 TLegend.cxx:935
 TLegend.cxx:936
 TLegend.cxx:937
 TLegend.cxx:938
 TLegend.cxx:939
 TLegend.cxx:940
 TLegend.cxx:941
 TLegend.cxx:942
 TLegend.cxx:943
 TLegend.cxx:944
 TLegend.cxx:945
 TLegend.cxx:946
 TLegend.cxx:947
 TLegend.cxx:948
 TLegend.cxx:949
 TLegend.cxx:950
 TLegend.cxx:951
 TLegend.cxx:952
 TLegend.cxx:953
 TLegend.cxx:954
 TLegend.cxx:955
 TLegend.cxx:956
 TLegend.cxx:957
 TLegend.cxx:958
 TLegend.cxx:959
 TLegend.cxx:960
 TLegend.cxx:961
 TLegend.cxx:962
 TLegend.cxx:963
 TLegend.cxx:964
 TLegend.cxx:965
 TLegend.cxx:966
 TLegend.cxx:967
 TLegend.cxx:968
 TLegend.cxx:969
 TLegend.cxx:970
 TLegend.cxx:971
 TLegend.cxx:972
 TLegend.cxx:973
 TLegend.cxx:974
 TLegend.cxx:975
 TLegend.cxx:976
 TLegend.cxx:977
 TLegend.cxx:978
 TLegend.cxx:979
 TLegend.cxx:980
 TLegend.cxx:981
 TLegend.cxx:982
 TLegend.cxx:983
 TLegend.cxx:984
 TLegend.cxx:985
 TLegend.cxx:986
 TLegend.cxx:987
 TLegend.cxx:988
 TLegend.cxx:989
 TLegend.cxx:990
 TLegend.cxx:991
 TLegend.cxx:992
 TLegend.cxx:993
 TLegend.cxx:994
 TLegend.cxx:995
 TLegend.cxx:996
 TLegend.cxx:997
 TLegend.cxx:998
 TLegend.cxx:999
 TLegend.cxx:1000
 TLegend.cxx:1001
 TLegend.cxx:1002
 TLegend.cxx:1003
 TLegend.cxx:1004
 TLegend.cxx:1005
 TLegend.cxx:1006
 TLegend.cxx:1007
 TLegend.cxx:1008
 TLegend.cxx:1009
 TLegend.cxx:1010
 TLegend.cxx:1011
 TLegend.cxx:1012
 TLegend.cxx:1013
 TLegend.cxx:1014
 TLegend.cxx:1015
 TLegend.cxx:1016
 TLegend.cxx:1017