<commit_before>// @(#)root/gui:$Id$
// Author: <NAME>   02/01/98

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

    This source is based on Xclass95, a Win95-looking GUI toolkit.
    Copyright (C) 1996, 1997 <NAME>, <NAME>, <NAME>.

    Xclass95 is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

**************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// A number of different layout classes (TGLayoutManager,               //
// TGVerticalLayout, TGHorizontalLayout, TGLayoutHints, etc.).          //
//                                                                      //
//                                                                      //
// Concerning the TGMatrixLayout class:                                 //
//                                                                      //
// It arranges frames in a matrix-like way.                             //
// This manager provides :                                              //
// - a column number (0 means unlimited)                                //
// - a row number (0 means unlimited)                                   //
// - horizontal & vertical separators                                   //
//                                                                      //
// Notes : If both column and row are fixed values, any remaining       //
//         frames outside the count won't be managed.                   //
//         Unlimited rows means the frame can expand downward           //
//         (the default behaviour in most UI).                          //
//         Both unlimited rows and columns is undefined (read: will     //
//         crash the algorithm ;-).                                     //
//         With fixed dimensions, frames are always arranged in rows.   //
//         That is: 1st frame is at position (0,0), next one is at      //
//         row(0), column(1) and so on...                               //
//         When specifying one dimension as unlimited (i.e. row=0 or    //
//         column=0) the frames are arranged according to the direction //
//         of the fixed dimension. This layout manager does not make    //
//         use of TGLayoutHints.                                        //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TGLayout.h"
#include "TGFrame.h"
#include "TList.h"
#include "Riostream.h"


ClassImp(TGLayoutHints)
ClassImp(TGLayoutManager)
ClassImp(TGVerticalLayout)
ClassImp(TGHorizontalLayout)
ClassImp(TGRowLayout)
ClassImp(TGColumnLayout)
ClassImp(TGMatrixLayout)
ClassImp(TGTileLayout)
ClassImp(TGListLayout)
ClassImp(TGListDetailsLayout)


//______________________________________________________________________________
TGFrameElement::TGFrameElement(TGFrame *f, TGLayoutHints *l)
{
   // Constructor.

   fLayout = 0;
   fFrame  = f;
   if (f) f->SetFrameElement(this);

   if (l) {
      l->AddReference();
      fLayout = l;
      l->fPrev = l->fFE;
      l->fFE = this;
   }
   fState = 1;
}

//______________________________________________________________________________
TGFrameElement::~TGFrameElement()
{
   // Destructor. Decrease ref. count of fLayout.

}

//______________________________________________________________________________
void TGFrameElement::Print(Option_t *option) const
{
   // Print this frame element.

   TObject::Print(option);

   std::cout << "\t";
   if (fFrame) {
      std::cout << fFrame->ClassName() << "::" << fFrame->GetName();
   }
   if (fLayout) {
      fLayout->Print(option);
   }
   std::cout << std::endl;
}

//______________________________________________________________________________
TGLayoutHints::TGLayoutHints(const TGLayoutHints &lh) : TObject(lh), TRefCnt(lh)
{
   // Constructor.

   fPadleft = lh.fPadleft; fPadright = lh.fPadright;
   fPadtop  = lh.fPadtop;  fPadbottom = lh.fPadbottom;
   fLayoutHints = lh.fLayoutHints;
   SetRefCount(0);
   fFE = lh.fFE; fPrev = lh.fPrev;
}

//______________________________________________________________________________
TGLayoutHints::~TGLayoutHints()
{
   // Destructor.

}

//______________________________________________________________________________
void TGLayoutHints::UpdateFrameElements(TGLayoutHints *l)
{
   // Update layout hints of frame elements.

   if (fFE) fFE->fLayout = l;
   else return;

   TGFrameElement *p = fPrev;

   while (p && p->fLayout) {
      p->fLayout = l;
      p = p->fLayout->fPrev;
   }
}

//______________________________________________________________________________
void TGLayoutHints::Print(Option_t *) const
{
   // Printing.

   Bool_t bor = kFALSE;

   if (fLayoutHints & kLHintsLeft) {
      std::cout << "kLHintsLeft";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsCenterX) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsCenterX";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsRight) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsRight";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsTop) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsTop";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsCenterY) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsCenterY";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsBottom) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsBottom";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsExpandX) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsExpandX";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsExpandY) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsExpandY";
      bor = kTRUE;
   }
   if (fLayoutHints == kLHintsNoHints) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsNoHints";
   }
   std::cout << ", fPadtop="    << fPadtop;
   std::cout << ", fPadbottom=" << fPadbottom;
   std::cout << ", fPadleft="   << fPadleft;
   std::cout << ", fPadright="  << fPadright;
   std::cout << std::endl;
}

//______________________________________________________________________________
TGVerticalLayout::TGVerticalLayout(TGCompositeFrame *main)
{
   // Create vertical layout manager.

   fMain = main;
   fList = fMain->GetList();
}

//______________________________________________________________________________
void TGVerticalLayout::Layout()
{
   // Make a vertical layout of all frames in the list.

   TGFrameElement *ptr;
   TGLayoutHints  *layout;
   Int_t    nb_expand = 0;
   Int_t    top, bottom;
   ULong_t  hints;
   UInt_t   extra_space = 0;
   Int_t    exp = 0;
   Int_t    exp_max = 0;
   Int_t    remain;
   Int_t    x = 0, y = 0;
   Int_t    bw = fMain->GetBorderWidth();
   TGDimension size(0,0), csize(0,0);
   TGDimension msize = fMain->GetSize();
   UInt_t pad_left, pad_top, pad_right, pad_bottom;
   Int_t size_expand=0, esize_expand=0, rem_expand=0, tmp_expand = 0;

   if (!fList) return;

   fModified = kFALSE;

   bottom = msize.fHeight - (top = bw);
   remain = msize.fHeight - (bw << 1);

   TIter next(fList);
   while ((ptr = (TGFrameElement *) next())) {
      if (ptr->fState & kIsVisible) {
         layout = ptr->fLayout;
         size = ptr->fFrame->GetDefaultSize();
         size.fHeight += layout->GetPadTop() + layout->GetPadBottom();
         hints = layout->GetLayoutHints();
         if ((hints & kLHintsExpandY) || (hints & kLHintsCenterY)) {
            nb_expand++;
            exp += size.fHeight;
            if (hints & kLHintsExpandY) exp_max = 0;
            else exp_max = TMath::Max(exp_max, (Int_t)size.fHeight);
         } else {
            remain -= size.fHeight;
            if (remain < 0)
               remain = 0;
         }
      }
   }

   if (nb_expand) {
      size_expand = remain/nb_expand;

      if (size_expand < exp_max)
         esize_expand = (remain - exp)/nb_expand;
      rem_expand = remain % nb_expand;
   }

   next.Reset();
   while ((ptr = (TGFrameElement *) next())) {
      if (ptr->fState & kIsVisible) {
         hints = (layout = ptr->fLayout)->GetLayoutHints();
         csize      = ptr->fFrame->GetDefaultSize();
         pad_left   = layout->GetPadLeft();
         pad_top    = layout->GetPadTop();
         pad_right  = layout->GetPadRight();
         pad_bottom = layout->GetPadBottom();

         if (hints & kLHintsRight) {
            x = msize.fWidth - bw - csize.fWidth - pad_right;
         } else if (hints & kLHintsCenterX) {
            x = (msize.fWidth - (bw << 1) - csize.fWidth) >> 1;
         } else { // defaults to kLHintsLeft
            x = pad_left + bw;
         }

         if (hints & kLHintsExpandX) {
            size.fWidth = msize.fWidth - (bw << 1) - pad_left - pad_right;
            x = pad_left + bw;
         } else {
            size.fWidth = csize.fWidth;
         }

         if (hints & kLHintsExpandY) {
            if (size_expand >= exp_max)
               size.fHeight = size_expand - pad_top - pad_bottom;
            else
               size.fHeight = csize.fHeight + esize_expand;

            tmp_expand += rem_expand;
            if (tmp_expand >= nb_expand) {
               size.fHeight++;
               tmp_expand -= nb_expand;
            }
         } else {
            size.fHeight = csize.fHeight;
            if (hints & kLHintsCenterY) {
               if (size_expand >= exp_max) {
                  extra_space = (size_expand - pad_top - pad_bottom - size.fHeight) >> 1;
               } else {
                  extra_space = esize_expand >> 1;
               }
               y += extra_space;
               top += extra_space;
            }
         }

         if (hints & kLHintsBottom) {
            y = bottom - size.fHeight - pad_bottom;
            bottom -= size.fHeight + pad_top + pad_bottom;
         } else { // kLHintsTop by default
            y = top + pad_top;
            top += size.fHeight + pad_top + pad_bottom;
         }

         if (hints & kLHintsCenterY)
            top += extra_space;

         if (x > 32768) x = bw + 1;
         if (y > 32768) y = bw + 1;
         if (size.fWidth > 32768)
            size.fWidth = 1;
         if (size.fHeight > 32768)
            size.fHeight = 1;
         ptr->fFrame->MoveResize(x, y, size.fWidth, size.fHeight);

         fModified = fModified || (ptr->fFrame->GetX() != x) ||
                    (ptr->fFrame->GetY() != y) ||
                    (ptr->fFrame->GetWidth() != size.fWidth) ||
                    (ptr->fFrame->GetHeight() != size.fHeight);
      }
   }
}

//______________________________________________________________________________
TGDimension TGVerticalLayout::GetDefaultSize() const
{
   // Return default dimension of the vertical layout.

   TGFrameElement *ptr;
   TGDimension     size(0,0), msize = fMain->GetSize(), csize;<commit_msg>Remove a limit check in layout calculation<commit_after>// @(#)root/gui:$Id$
// Author: <NAME>   02/01/98

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

    This source is based on Xclass95, a Win95-looking GUI toolkit.
    Copyright (C) 1996, 1997 <NAME>, <NAME>, <NAME>.

    Xclass95 is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

**************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// A number of different layout classes (TGLayoutManager,               //
// TGVerticalLayout, TGHorizontalLayout, TGLayoutHints, etc.).          //
//                                                                      //
//                                                                      //
// Concerning the TGMatrixLayout class:                                 //
//                                                                      //
// It arranges frames in a matrix-like way.                             //
// This manager provides :                                              //
// - a column number (0 means unlimited)                                //
// - a row number (0 means unlimited)                                   //
// - horizontal & vertical separators                                   //
//                                                                      //
// Notes : If both column and row are fixed values, any remaining       //
//         frames outside the count won't be managed.                   //
//         Unlimited rows means the frame can expand downward           //
//         (the default behaviour in most UI).                          //
//         Both unlimited rows and columns is undefined (read: will     //
//         crash the algorithm ;-).                                     //
//         With fixed dimensions, frames are always arranged in rows.   //
//         That is: 1st frame is at position (0,0), next one is at      //
//         row(0), column(1) and so on...                               //
//         When specifying one dimension as unlimited (i.e. row=0 or    //
//         column=0) the frames are arranged according to the direction //
//         of the fixed dimension. This layout manager does not make    //
//         use of TGLayoutHints.                                        //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TGLayout.h"
#include "TGFrame.h"
#include "TList.h"
#include "Riostream.h"


ClassImp(TGLayoutHints)
ClassImp(TGLayoutManager)
ClassImp(TGVerticalLayout)
ClassImp(TGHorizontalLayout)
ClassImp(TGRowLayout)
ClassImp(TGColumnLayout)
ClassImp(TGMatrixLayout)
ClassImp(TGTileLayout)
ClassImp(TGListLayout)
ClassImp(TGListDetailsLayout)


//______________________________________________________________________________
TGFrameElement::TGFrameElement(TGFrame *f, TGLayoutHints *l)
{
   // Constructor.

   fLayout = 0;
   fFrame  = f;
   if (f) f->SetFrameElement(this);

   if (l) {
      l->AddReference();
      fLayout = l;
      l->fPrev = l->fFE;
      l->fFE = this;
   }
   fState = 1;
}

//______________________________________________________________________________
TGFrameElement::~TGFrameElement()
{
   // Destructor. Decrease ref. count of fLayout.

}

//______________________________________________________________________________
void TGFrameElement::Print(Option_t *option) const
{
   // Print this frame element.

   TObject::Print(option);

   std::cout << "\t";
   if (fFrame) {
      std::cout << fFrame->ClassName() << "::" << fFrame->GetName();
   }
   if (fLayout) {
      fLayout->Print(option);
   }
   std::cout << std::endl;
}

//______________________________________________________________________________
TGLayoutHints::TGLayoutHints(const TGLayoutHints &lh) : TObject(lh), TRefCnt(lh)
{
   // Constructor.

   fPadleft = lh.fPadleft; fPadright = lh.fPadright;
   fPadtop  = lh.fPadtop;  fPadbottom = lh.fPadbottom;
   fLayoutHints = lh.fLayoutHints;
   SetRefCount(0);
   fFE = lh.fFE; fPrev = lh.fPrev;
}

//______________________________________________________________________________
TGLayoutHints::~TGLayoutHints()
{
   // Destructor.

}

//______________________________________________________________________________
void TGLayoutHints::UpdateFrameElements(TGLayoutHints *l)
{
   // Update layout hints of frame elements.

   if (fFE) fFE->fLayout = l;
   else return;

   TGFrameElement *p = fPrev;

   while (p && p->fLayout) {
      p->fLayout = l;
      p = p->fLayout->fPrev;
   }
}

//______________________________________________________________________________
void TGLayoutHints::Print(Option_t *) const
{
   // Printing.

   Bool_t bor = kFALSE;

   if (fLayoutHints & kLHintsLeft) {
      std::cout << "kLHintsLeft";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsCenterX) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsCenterX";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsRight) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsRight";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsTop) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsTop";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsCenterY) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsCenterY";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsBottom) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsBottom";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsExpandX) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsExpandX";
      bor = kTRUE;
   }
   if (fLayoutHints & kLHintsExpandY) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsExpandY";
      bor = kTRUE;
   }
   if (fLayoutHints == kLHintsNoHints) {
      if (bor) std::cout << " | ";
      std::cout << "kLHintsNoHints";
   }
   std::cout << ", fPadtop="    << fPadtop;
   std::cout << ", fPadbottom=" << fPadbottom;
   std::cout << ", fPadleft="   << fPadleft;
   std::cout << ", fPadright="  << fPadright;
   std::cout << std::endl;
}

//______________________________________________________________________________
TGVerticalLayout::TGVerticalLayout(TGCompositeFrame *main)
{
   // Create vertical layout manager.

   fMain = main;
   fList = fMain->GetList();
}

//______________________________________________________________________________
void TGVerticalLayout::Layout()
{
   // Make a vertical layout of all frames in the list.

   TGFrameElement *ptr;
   TGLayoutHints  *layout;
   Int_t    nb_expand = 0;
   Int_t    top, bottom;
   ULong_t  hints;
   UInt_t   extra_space = 0;
   Int_t    exp = 0;
   Int_t    exp_max = 0;
   Int_t    remain;
   Int_t    x = 0, y = 0;
   Int_t    bw = fMain->GetBorderWidth();
   TGDimension size(0,0), csize(0,0);
   TGDimension msize = fMain->GetSize();
   UInt_t pad_left, pad_top, pad_right, pad_bottom;
   Int_t size_expand=0, esize_expand=0, rem_expand=0, tmp_expand = 0;

   if (!fList) return;

   fModified = kFALSE;

   bottom = msize.fHeight - (top = bw);
   remain = msize.fHeight - (bw << 1);

   TIter next(fList);
   while ((ptr = (TGFrameElement *) next())) {
      if (ptr->fState & kIsVisible) {
         layout = ptr->fLayout;
         size = ptr->fFrame->GetDefaultSize();
         size.fHeight += layout->GetPadTop() + layout->GetPadBottom();
         hints = layout->GetLayoutHints();
         if ((hints & kLHintsExpandY) || (hints & kLHintsCenterY)) {
            nb_expand++;
            exp += size.fHeight;
            if (hints & kLHintsExpandY) exp_max = 0;
            else exp_max = TMath::Max(exp_max, (Int_t)size.fHeight);
         } else {
            remain -= size.fHeight;
            if (remain < 0)
               remain = 0;
         }
      }
   }

   if (nb_expand) {
      size_expand = remain/nb_expand;

      if (size_expand < exp_max)
         esize_expand = (remain - exp)/nb_expand;
      rem_expand = remain % nb_expand;
   }

   next.Reset();
   while ((ptr = (TGFrameElement *) next())) {
      if (ptr->fState & kIsVisible) {
         hints = (layout = ptr->fLayout)->GetLayoutHints();
         csize      = ptr->fFrame->GetDefaultSize();
         pad_left   = layout->GetPadLeft();
         pad_top    = layout->GetPadTop();
         pad_right  = layout->GetPadRight();
         pad_bottom = layout->GetPadBottom();

         if (hints & kLHintsRight) {
            x = msize.fWidth - bw - csize.fWidth - pad_right;
         } else if (hints & kLHintsCenterX) {
            x = (msize.fWidth - (bw << 1) - csize.fWidth) >> 1;
         } else { // defaults to kLHintsLeft
            x = pad_left + bw;
         }

         if (hints & kLHintsExpandX) {
            size.fWidth = msize.fWidth - (bw << 1) - pad_left - pad_right;
            x = pad_left + bw;
         } else {
            size.fWidth = csize.fWidth;
         }

         if (hints & kLHintsExpandY) {
            if (size_expand >= exp_max)
               size.fHeight = size_expand - pad_top - pad_bottom;
            else
               size.fHeight = csize.fHeight + esize_expand;

            tmp_expand += rem_expand;
            if (tmp_expand >= nb_expand) {
               size.fHeight++;
               tmp_expand -= nb_expand;
            }
         } else {
            size.fHeight = csize.fHeight;
            if (hints & kLHintsCenterY) {
               if (size_expand >= exp_max) {
                  extra_space = (size_expand - pad_top - pad_bottom - size.fHeight) >> 1;
               } else {
                  extra_space = esize_expand >> 1;
               }
               y += extra_space;
               top += extra_space;
            }
         }

         if (hints & kLHintsBottom) {
            y = bottom - size.fHeight - pad_bottom;
            bottom -= size.fHeight + pad_top + pad_bottom;
         } else { // kLHintsTop by default
            y = top + pad_top;
            top += size.fHeight + pad_top + pad_bottom;
         }

         if (hints & kLHintsCenterY)
            top += extra_space;

         if (x > 32768) x = bw + 1;
         //if (y > 32768) y = bw + 1;
         if (size.fWidth > 32768)
            size.fWidth = 1;
         if (size.fHeight > 32768)
            size.fHeight = 1;
         ptr->fFrame->MoveResize(x, y, size.fWidth, size.fHeight);

         fModified = fModified || (ptr->fFrame->GetX() != x) ||
                    (ptr->fFrame->GetY() != y) ||
                    (ptr->fFrame->GetWidth() != size.fWidth) ||
                    (ptr->fFrame->GetHeight() != size.fHeight);
      }
   }
}

//______________________________________________________________________________
TGDimension TGVerticalLayout::GetDefaultSize() const
{
   // Return default dimension of the vertical layout.

   TGFrameElement *ptr;
   TGDimension     size(0,0), msize = fMain->GetSize(), csize;
{'fraction_non_alphanumeric': 0.1513798528723902, 'fraction_numerical': 0.007654037504783774, 'mean_word_length': 1.7645468437757141, 'pattern_counts': {'":': 2, '<': 155, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 58, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7186820', 'n_tokens_mistral': 6930, 'n_tokens_neox': 6570, 'n_words': 1553}