TGTableLayout.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGTableLayout.cxx 34223 2010-06-30 11:01:48Z bellenot $
00002 // Author: Brett Viren   04/15/2001
00003 
00004 /*************************************************************************
00005  * Copyright (C) 2001, Brett Viren                                       *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 /**************************************************************************
00012 
00013     This source is based on Xclass95, a Win95-looking GUI toolkit.
00014     Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
00015 
00016     Xclass95 is free software; you can redistribute it and/or
00017     modify it under the terms of the GNU Library General Public
00018     License as published by the Free Software Foundation; either
00019     version 2 of the License, or (at your option) any later version.
00020 
00021 **************************************************************************/
00022 /**************************************************************************
00023 
00024     The Layout algorithm was largely translated from GTK's gtktable.c
00025     source.  That source is also distributed under LGPL.
00026 
00027 **************************************************************************/
00028 
00029 //////////////////////////////////////////////////////////////////////////
00030 //                                                                      //
00031 // TGTableLayout                                                        //
00032 //                                                                      //
00033 // A layout manager, which places child frames in a table arranged in   //
00034 // rows and columns, making it easy to align many widgets next each to  //
00035 // other horizontally and vertivally. It uses TGTableLayoutHints        //
00036 // (not TGLayoutHints!!!) and works like TGMatrixLayout with the        //
00037 // addition that:                                                       //
00038 //  - Child frames can span more than one column/row.                   //
00039 //  - Child frames can resize with the frame.                           //
00040 //  - Column and row sizes are not fixed nor (optionally) homogeneous.  //
00041 //  - The number of columns and rows must be fully specified in the     //
00042 //    constructor.                                                      //
00043 // The gaps between all rows or columns can be specified by 'sep'       //
00044 // parameter in the constructor. All rows and columns will have the     //
00045 // same size (set by widest and the highest child frame) if the         //
00046 // parameter 'homogeneous' is set to kTRUE.                             //
00047 //                                                                      //
00048 //                                                                      //
00049 // TGTableLayoutHints                                                   //
00050 //                                                                      //
00051 // This class describes layout hints used by the TGTableLayout class.   //
00052 // It specifies the column/row division number on which to attach the   //
00053 // child frame. This number starts from 0 and goes to #_columns/#_rows  //
00054 // respectively (0 indicates the first row/column).                     //
00055 //                                                                      //
00056 // Below are described all parameters of TGTableLayoutHints constructor //
00057 //     attach_left   - the column to the left of the widget;            //
00058 //     attach_right  - the column to the right of the widget;           //
00059 //     attach_top    - the row above the widget;                        //
00060 //     attach_bottom - the row below the widget;                        //
00061 //                                                                      //
00062 //     hints - layout hints (combination of ELayoutHints)               //
00063 //                                                                      //
00064 // The next parameters determine the extra padding added around the     //
00065 // child frame. By default these are 0.                                 //
00066 //     padleft   - determines the extra padding added on the left       //
00067 //     padright  - determines the extra padding added on the right      //
00068 //     padtop    - determines the extra padding added on the top        //
00069 //     padbottom - determines the extra padding added on the bottom     //
00070 //                                                                      //
00071 //////////////////////////////////////////////////////////////////////////
00072 
00073 
00074 #include "TGTableLayout.h"
00075 #include "TGFrame.h"
00076 #include "TList.h"
00077 #include "Rtypes.h"
00078 #include "Riostream.h"
00079 
00080 
00081 ClassImp(TGTableLayout)
00082 ClassImp(TGTableLayoutHints)
00083 
00084 //______________________________________________________________________________
00085 TGTableLayout::TGTableLayout(TGCompositeFrame *main, UInt_t nrows, UInt_t ncols,
00086                              Bool_t homogeneous, Int_t sep, Int_t hints)
00087 {
00088    // TGTableLayout constructor.
00089    // Note:
00090    // - Number of rows first, number of Columns second
00091    // - homogeneous == true means all table cells are the same size,
00092    //   set by the widest and the highest child frame.
00093    // - s gives the amount of separation in pixels between cells
00094    // - h are the hints, see TGTableLayoutHints.
00095 
00096    fMain    = main;
00097    fList    = fMain->GetList();
00098    fSep     = sep;
00099    fHints   = hints;
00100    fNrows   = nrows;
00101    fNcols   = ncols;
00102    fRow     = 0;
00103    fCol     = 0;
00104    fHomogeneous = homogeneous;
00105 }
00106 
00107 //______________________________________________________________________________
00108 TGTableLayout::~TGTableLayout()
00109 {
00110    // TGTableLayout constructor.
00111 
00112    if (fRow) delete [] fRow;
00113    if (fCol) delete [] fCol;
00114 }
00115 
00116 //______________________________________________________________________________
00117 void TGTableLayout::FindRowColSizes()
00118 {
00119    // Find the sizes of rows and columns needed to statisfy
00120    // children's layout policies.
00121 
00122    // This is equiv to GTK's requisition stage
00123 
00124    FindRowColSizesInit();
00125    FindRowColSizesSinglyAttached();
00126    FindRowColSizesHomogeneous();
00127    FindRowColSizesMultiplyAttached();
00128    FindRowColSizesHomogeneous();
00129 }
00130 
00131 //______________________________________________________________________________
00132 void TGTableLayout::FindRowColSizesInit()
00133 {
00134    // Initialize values needed to determine the size of rows and columns.
00135 
00136    if (fRow) delete [] fRow;
00137    if (fCol) delete [] fCol;
00138    fRow = new TableData_t[fNrows];
00139    fCol = new TableData_t[fNcols];
00140 
00141    // Find max of each row and column
00142 
00143    UInt_t i;
00144    for (i = 0; i < fNrows; ++i) fRow[i].fDefSize = 0;
00145    for (i = 0; i < fNcols; ++i) fCol[i].fDefSize = 0;
00146 }
00147 
00148 //______________________________________________________________________________
00149 void TGTableLayout::FindRowColSizesSinglyAttached()
00150 {
00151    // Determine the size of rows/cols needed for singly attached children.
00152 
00153    TIter next(fList);
00154    TGFrameElement *ptr;
00155 
00156    while ((ptr = (TGFrameElement *) next())) {
00157       if (ptr->fState == 0) continue;
00158       TGTableLayoutHints *layout =
00159             dynamic_cast<TGTableLayoutHints*>(ptr->fLayout);
00160       if (!layout) {
00161          Error("FindRowColSizesSinglyAttached", "didn't get TGTableLayoutHints from %s, layout = 0x%lx",
00162                ptr->fFrame->GetName(), (ULong_t)ptr->fLayout);
00163          return;
00164       }
00165       UInt_t col = layout->GetAttachLeft();
00166       if (col == (layout->GetAttachRight() - 1))
00167          fCol[col].fDefSize = TMath::Max(fCol[col].fDefSize,
00168                                          ptr->fFrame->GetDefaultWidth() +
00169                                          layout->GetPadLeft() +
00170                                          layout->GetPadRight());
00171 
00172       UInt_t row = layout->GetAttachTop();
00173       if (row == (layout->GetAttachBottom() - 1))
00174          fRow[row].fDefSize = TMath::Max(fRow[row].fDefSize,
00175                                          ptr->fFrame->GetDefaultHeight() +
00176                                          layout->GetPadTop() +
00177                                          layout->GetPadBottom());
00178    }
00179 }
00180 
00181 //______________________________________________________________________________
00182 void TGTableLayout::FindRowColSizesHomogeneous()
00183 {
00184    // If the table is homogeneous make sure all col/rows are same
00185    // size as biggest col/row.
00186 
00187    if (!fHomogeneous) return;
00188 
00189    UInt_t max_width = 0, max_height = 0, col, row;
00190 
00191    // find max
00192    for (col = 0; col < fNcols; ++col)
00193       max_width = TMath::Max(max_width,fCol[col].fDefSize);
00194 
00195    for (row = 0; row < fNrows; ++row)
00196       max_height = TMath::Max(max_height,fRow[row].fDefSize);
00197 
00198    // set max
00199    for (col = 0; col < fNcols; ++col) fCol[col].fDefSize = max_width;
00200    for (row = 0; row < fNrows; ++row) fRow[row].fDefSize = max_height;
00201 }
00202 
00203 //______________________________________________________________________________
00204 void TGTableLayout::FindRowColSizesMultiplyAttached()
00205 {
00206    // Checks any children which span multiple col/rows.
00207 
00208    TIter next(fList);
00209    TGFrameElement *ptr;
00210 
00211    while ((ptr = (TGFrameElement *) next())) {
00212       if (ptr->fState == 0) continue;
00213       TGTableLayoutHints *layout =
00214             dynamic_cast<TGTableLayoutHints*>(ptr->fLayout);
00215       if (!layout) {
00216          Error("FindRowColSizesMultiplyAttached", "didn't get TGTableLayoutHints");
00217          return;
00218       }
00219       UInt_t left   = layout->GetAttachLeft();
00220       UInt_t right  = layout->GetAttachRight();
00221       if (left != right-1) {  // child spans multi-columns
00222          UInt_t width = 0, col;
00223          for (col = left; col < right; ++col) width += fCol[col].fDefSize;
00224 
00225          // If more space needed, divide space evenly among the columns
00226          UInt_t child_width = ptr->fFrame->GetDefaultWidth() +
00227                               layout->GetPadLeft() + layout->GetPadRight();
00228 
00229          if (width < child_width) {
00230             width = child_width - width;
00231             for (col = left; col < right; ++col) {
00232                UInt_t extra = width / (right - col);
00233                fCol[col].fDefSize += extra;
00234                width -= extra;
00235             }
00236          }
00237       }
00238       UInt_t top    = layout->GetAttachTop();
00239       UInt_t bottom = layout->GetAttachBottom();
00240       if (top != bottom-1) {  // child spans multi-rows
00241          UInt_t height = 0, row;
00242          for (row = top; row < bottom; ++row) height += fRow[row].fDefSize;
00243 
00244          // If more space needed, divide space evenly among the rows
00245          UInt_t child_height = ptr->fFrame->GetDefaultHeight() +
00246                                layout->GetPadTop() + layout->GetPadBottom();
00247 
00248          if (height < child_height) {
00249             height = child_height - height;
00250             for (row = top; row < bottom; ++row) {
00251                UInt_t extra = height / (bottom - row);
00252                fRow[row].fDefSize += extra;
00253                height -= extra;
00254             }
00255          }
00256       }
00257    }
00258 }
00259 
00260 //______________________________________________________________________________
00261 void TGTableLayout::SetRowColResize(UInt_t real_size, UInt_t nthings,
00262                                     TableData_t *thing, Bool_t homogeneous)
00263 {
00264    // If main frame is bigger or smaller than all children,
00265    // expand/shrink to fill. This is symmetric under row<-->col
00266    // switching so it is abstracted out to a normal function to save typing.
00267 
00268    if (homogeneous) {
00269       UInt_t ind, nshrink=0, nexpand=0, cur_size=0;
00270 
00271       for (ind = 0; ind < nthings; ++ind)
00272          cur_size += thing[ind].fDefSize;
00273 
00274       if (cur_size < real_size) {
00275          for (ind = 0; ind < nthings; ++ind)
00276             if (thing[ind].fExpand) { ++ nexpand; break; }
00277          if (nexpand > 0) {
00278             UInt_t size = real_size;
00279             for (ind = 0; ind < nthings; ++ ind) {
00280                UInt_t extra = size / (nthings - ind);
00281                thing[ind].fRealSize = TMath::Max(1U, extra);
00282                size -= extra;
00283             }
00284          }
00285       }
00286       if (cur_size > real_size) {
00287          for (ind = 0; ind < nthings; ++ind)
00288             if (thing[ind].fShrink) { ++ nshrink; break; }
00289          if (nshrink > 0) {
00290             UInt_t size = real_size;
00291             for (ind = 0; ind < nthings; ++ ind) {
00292                UInt_t extra = size / (nthings - ind);
00293                thing[ind].fRealSize = TMath::Max(1U, extra);
00294                size -= extra;
00295             }
00296          }
00297       }
00298    } else {
00299       UInt_t ind, nshrink=0, nexpand=0, size=0;
00300       for (ind = 0; ind < nthings; ++ind) {
00301          size += thing[ind].fDefSize;
00302          if (thing[ind].fExpand) ++ nexpand;
00303          if (thing[ind].fShrink) ++ nshrink;
00304       }
00305 
00306       // Did main frame expand?
00307       if ((size < real_size) && (nexpand >= 1)) {
00308          size = real_size - size;
00309          for (ind = 0; ind < nthings; ++ind) {
00310             if (thing[ind].fExpand) {
00311                UInt_t extra = size / nexpand;
00312                thing[ind].fRealSize += extra;
00313                size -= extra;
00314                --nexpand;
00315             }
00316          }
00317       }
00318 
00319       // Did main frame shrink?
00320       if (size > real_size) {
00321          UInt_t total_nshrink = nshrink;
00322          UInt_t extra = size - real_size;
00323          while (total_nshrink > 0 && extra > 0) {
00324             nshrink = total_nshrink;
00325             for (ind = 0; ind < nthings; ++ind)
00326                if (thing[ind].fShrink) {
00327                   UInt_t size2 = thing[ind].fRealSize;
00328                   thing[ind].fRealSize = TMath::Max(1U,thing[ind].fRealSize - extra / nshrink);
00329                   extra -= size2 - thing[ind].fRealSize;
00330                   --nshrink;
00331                   if (thing[ind].fRealSize < 2) {
00332                      total_nshrink -= 1;
00333                      thing[ind].fShrink = kFALSE;
00334                   }
00335                }
00336          }
00337       }
00338    } // not homogeneous
00339 }
00340 
00341 //______________________________________________________________________________
00342 void TGTableLayout::SetRowColSizes()
00343 {
00344    // This gets the new sizes needed to fit the table to the parent
00345    // frame. To be called after FindRowColSizes.
00346 
00347    SetRowColSizesInit();
00348    UInt_t border_width = fMain->GetBorderWidth();
00349 
00350    SetRowColResize(fMain->GetWidth() - (fNcols-1)*fSep - 2*border_width,
00351                    fNcols, fCol, fHomogeneous);
00352    SetRowColResize(fMain->GetHeight() - (fNrows-1)*fSep - 2*border_width,
00353                    fNrows, fRow, fHomogeneous);
00354 }
00355 
00356 //______________________________________________________________________________
00357 void TGTableLayout::SetRowColSizesInit()
00358 {
00359    // Initialize rows/cols. By default they do not expand and they
00360    // do shrink. What the children want determine what the rows/cols do.
00361 
00362    UInt_t col;
00363    for (col = 0; col < fNcols; ++col) {
00364       fCol[col].fRealSize = fCol[col].fDefSize;
00365       fCol[col].fNeedExpand = kFALSE;
00366       fCol[col].fNeedShrink = kTRUE;
00367       fCol[col].fExpand = kFALSE;
00368       fCol[col].fShrink = kTRUE;
00369       fCol[col].fEmpty = kTRUE;
00370    }
00371    UInt_t row;
00372    for (row = 0; row < fNrows; ++row) {
00373       fRow[row].fRealSize = fRow[row].fDefSize;
00374       fRow[row].fNeedExpand = kFALSE;
00375       fRow[row].fNeedShrink = kTRUE;
00376       fRow[row].fExpand = kFALSE;
00377       fRow[row].fShrink = kTRUE;
00378       fRow[row].fEmpty = kTRUE;
00379    }
00380 
00381    // Check single row/col children for expand/shrink-ability
00382    TIter next(fList);
00383    TGFrameElement *ptr;
00384    while ((ptr = (TGFrameElement*) next())) {
00385       TGTableLayoutHints *layout =
00386             dynamic_cast<TGTableLayoutHints*>(ptr->fLayout);
00387       if (!layout) {
00388          Error("SetRowColSizesInit", "didn't get TGTableLayoutHints");
00389          return;
00390       }
00391       ULong_t hints = layout->GetLayoutHints();
00392 
00393       // columns
00394       if (layout->GetAttachLeft() == layout->GetAttachRight()-1) {
00395          if (hints & kLHintsExpandX)
00396             fCol[layout->GetAttachLeft()].fExpand = kTRUE;
00397          if (!(hints & kLHintsShrinkX))
00398             fCol[layout->GetAttachLeft()].fShrink = kFALSE;
00399          fCol[layout->GetAttachLeft()].fEmpty = kFALSE;
00400       }
00401       // rows
00402       if (layout->GetAttachTop() == layout->GetAttachBottom()-1) {
00403          if (hints & kLHintsExpandY)
00404             fRow[layout->GetAttachTop()].fExpand = kTRUE;
00405          if (!(hints & kLHintsShrinkY))
00406             fRow[layout->GetAttachTop()].fShrink = kFALSE;
00407          fRow[layout->GetAttachTop()].fEmpty = kFALSE;
00408       }
00409    }
00410 
00411    // Do same for children of spanning multiple col/rows
00412    next.Reset();
00413    while ((ptr = (TGFrameElement*) next())) {
00414       TGTableLayoutHints *layout =
00415             dynamic_cast<TGTableLayoutHints*>(ptr->fLayout);
00416       if (!layout) {
00417          Error("SetRowColSizesInit", "didn't get TGTableLayoutHints");
00418          return;
00419       }
00420       ULong_t hints = layout->GetLayoutHints();
00421 
00422       // columns
00423       UInt_t left = layout->GetAttachLeft();
00424       UInt_t right = layout->GetAttachRight();
00425       if (left != right - 1) {
00426          for (col = left; col < right; ++col) fCol[col].fEmpty = kFALSE;
00427          Bool_t has_expand=kFALSE, has_shrink=kTRUE;
00428          if (hints & kLHintsExpandX) {
00429             for (col = left; col < right; ++col)
00430                if (fCol[col].fExpand) { has_expand = kTRUE; break; }
00431             if (!has_expand)
00432                for (col = left; col < right; ++col)
00433                   fCol[col].fNeedExpand = kTRUE;
00434          }
00435          if (!(hints & kLHintsShrinkX)) {
00436             for (col = left; col < right; ++col)
00437                if (!fCol[col].fShrink) { has_shrink = kFALSE; break;}
00438             if (has_shrink)
00439                for (col = left; col < right; ++col)
00440                   fCol[col].fNeedShrink = kFALSE;
00441          }
00442       }
00443 
00444       // rows
00445       UInt_t top = layout->GetAttachTop();
00446       UInt_t bottom = layout->GetAttachBottom();
00447       if (top != bottom - 1) {
00448          for (row = top; row < bottom; ++row) fRow[row].fEmpty = kFALSE;
00449          Bool_t has_expand=kFALSE, has_shrink=kTRUE;
00450          if (hints & kLHintsExpandY) {
00451             for (row = top; row < bottom; ++row)
00452                if (fRow[row].fExpand) { has_expand = kTRUE; break; }
00453             if (!has_expand)
00454                for (row = top; row < bottom; ++row)
00455                   fRow[row].fNeedExpand = kTRUE;
00456          }
00457          if (!(hints & kLHintsShrinkY)) {
00458             for (row = top; row < bottom; ++row)
00459                if (!fRow[row].fShrink) { has_shrink = kFALSE; break;}
00460             if (has_shrink)
00461                for (row = top; row < bottom; ++row)
00462                   fRow[row].fNeedShrink = kFALSE;
00463          }
00464       }
00465    }
00466 
00467    // Set expand/shrink flags
00468    for (col = 0; col < fNcols; ++col) {
00469       if (fCol[col].fEmpty) {
00470          fCol[col].fExpand = kFALSE;
00471          fCol[col].fShrink = kFALSE;
00472       } else {
00473          if (fCol[col].fNeedExpand) fCol[col].fExpand = kTRUE;
00474          if (!fCol[col].fNeedShrink) fCol[col].fShrink = kFALSE;
00475       }
00476    }
00477    for (row = 0; row < fNrows; ++row) {
00478       if (fRow[row].fEmpty) {
00479          fRow[row].fExpand = kFALSE;
00480          fRow[row].fShrink = kFALSE;
00481       } else {
00482          if (fRow[row].fNeedExpand) fRow[row].fExpand = kTRUE;
00483          if (!fRow[row].fNeedShrink) fRow[row].fShrink = kFALSE;
00484       }
00485    }
00486 }
00487 
00488 //______________________________________________________________________________
00489 void TGTableLayout::CheckSanity()
00490 {
00491    // Sanity check various values.
00492 
00493    TIter next(fList);
00494    TGFrameElement *ptr;
00495    UInt_t nerrors = 0;
00496    while ((ptr = (TGFrameElement*) next())) {
00497       TGTableLayoutHints *layout =
00498             dynamic_cast<TGTableLayoutHints*>(ptr->fLayout);
00499       if (!layout) {
00500          Error("CheckSanity", "didn't get TGTableLayoutHints");
00501          return;
00502       }
00503 
00504       UInt_t right  = layout->GetAttachRight();
00505       UInt_t left   = layout->GetAttachLeft();
00506       UInt_t top    = layout->GetAttachTop();
00507       UInt_t bottom = layout->GetAttachBottom();
00508 
00509       if (left == right) {
00510          ++nerrors;
00511          Error("CheckSanity", "AttachLeft == AttachRight");
00512       }
00513       if (left > right) {
00514          ++nerrors;
00515          Error("CheckSanity", "AttachLeft > AttachRight");
00516       }
00517       if (left > fNcols-1) {
00518          ++nerrors;
00519          Error("CheckSanity", "AttachLeft illegal value: %u", left);
00520       }
00521       if (right < 1 || right > fNcols) {
00522          ++nerrors;
00523          Error("CheckSanity", "AttachRight illegal value: %u", right);
00524       }
00525 
00526       if (top == bottom) {
00527          ++nerrors;
00528          Error("CheckSanity", "AttachTop == AttachBottom");
00529       }
00530       if (top > bottom) {
00531          ++nerrors;
00532          Error("CheckSanity", "AttachTop > AttachBottom");
00533       }
00534       if (top > fNrows-1) {
00535          ++nerrors;
00536          Error("CheckSanity", "AttachTop illegal value: %u", top);
00537       }
00538       if (bottom < 1 || bottom > fNrows) {
00539          ++nerrors;
00540          Error("CheckSanity", "AttachBottom illegal value: %u", bottom);
00541       }
00542 
00543    }
00544    if (nerrors) {
00545       Error("CheckSanity", "errors in %u x %u table", fNcols, fNrows);
00546    }
00547 }
00548 
00549 //______________________________________________________________________________
00550 void TGTableLayout::Layout()
00551 {
00552     // Make a table layout of all frames in the list.
00553 
00554    CheckSanity();
00555 
00556    FindRowColSizes();
00557 
00558    SetRowColSizes();
00559 
00560    // Do the layout
00561    TIter next(fList);
00562    TGFrameElement *ptr;
00563    UInt_t border_width = fMain->GetBorderWidth();
00564    while ((ptr = (TGFrameElement*) next())) {
00565       TGTableLayoutHints *layout = 
00566             dynamic_cast<TGTableLayoutHints*>(ptr->fLayout);
00567       if (!layout) {
00568          Error("TGTableLayout::Layout", "didn't get TGTableLayoutHints");
00569          return;
00570       }
00571       ULong_t hints = layout->GetLayoutHints();
00572       TGDimension size = ptr->fFrame->GetDefaultSize();
00573 
00574       UInt_t right  = layout->GetAttachRight();
00575       UInt_t left   = layout->GetAttachLeft();
00576       UInt_t top    = layout->GetAttachTop();
00577       UInt_t bottom = layout->GetAttachBottom();
00578 
00579       // Find location and size of cell in which to fit the child frame.
00580       UInt_t col, cell_x = border_width + left*fSep;
00581       for (col = 0; col < left; ++col) cell_x += fCol[col].fRealSize;
00582 
00583       UInt_t row, cell_y = border_width + top*fSep;
00584       for (row = 0; row < top; ++row) cell_y += fRow[row].fRealSize;
00585 
00586       UInt_t cell_width = (right-left-1)*fSep;
00587       for (col=left; col < right; ++col)
00588          cell_width += fCol[col].fRealSize;
00589 
00590       UInt_t cell_height = (bottom-top-1)*fSep;
00591       for (row=top; row < bottom; ++row)
00592          cell_height += fRow[row].fRealSize;
00593 
00594       UInt_t pad_left   = layout->GetPadLeft();
00595       UInt_t pad_right  = layout->GetPadRight();
00596       UInt_t pad_bottom = layout->GetPadBottom();
00597       UInt_t pad_top    = layout->GetPadTop();
00598 
00599       // find size of child frame
00600       UInt_t ww,hh;
00601       if (hints & kLHintsFillX)
00602          ww = cell_width  - pad_left - pad_right;
00603       else
00604          ww = size.fWidth;
00605       if (hints & kLHintsFillY)
00606          hh = cell_height - pad_top - pad_bottom;
00607       else
00608          hh = size.fHeight;
00609 
00610       // Find location of child frame
00611       UInt_t xx;
00612       if (hints & kLHintsFillX) // Fill beats right/center/left hints
00613          xx = cell_x + pad_left;
00614       else if (hints & kLHintsRight)
00615          xx = cell_x + cell_width - pad_right - ww;
00616       else if (hints & kLHintsCenterX)
00617          xx = cell_x + cell_width/2 - ww/2; // padding?
00618       else                    // defaults to kLHintsLeft
00619          xx = cell_x + pad_left;
00620 
00621       UInt_t yy;
00622       if (hints & kLHintsFillY) // Fill beats top/center/bottom hings
00623          yy = cell_y + pad_top;
00624       else if (hints & kLHintsBottom)
00625          yy = cell_y + cell_height - pad_bottom - hh;
00626       else if (hints & kLHintsCenterY)
00627          yy = cell_y + cell_height/2 - hh/2; // padding?
00628       else                    // defaults to kLHintsTop
00629          yy = cell_y + pad_top;
00630 
00631       ptr->fFrame->MoveResize(xx,yy,ww,hh);
00632       ptr->fFrame->Layout();
00633 
00634    }
00635 }
00636 
00637 //______________________________________________________________________________
00638 TGDimension TGTableLayout::GetDefaultSize() const
00639 {
00640    // Return default dimension of the table layout.
00641 
00642    TGDimension msize = fMain->GetSize();
00643    UInt_t options = fMain->GetOptions();
00644 
00645    if ((options & kFixedWidth) && (options & kFixedHeight))
00646       return msize;
00647 
00648    Int_t border_width = fMain->GetBorderWidth();
00649 
00650    TGDimension size(2*border_width + (fNcols-1)*fSep,
00651                     2*border_width + (fNrows-1)*fSep);
00652 
00653    UInt_t col, row;
00654    if (fCol)
00655       for (col = 0; col < fNcols; ++col) size.fWidth += fCol[col].fDefSize;
00656    if (fRow)
00657       for (row = 0; row < fNrows; ++row) size.fHeight += fRow[row].fDefSize;
00658 
00659    if (options & kFixedWidth)  size.fWidth = msize.fWidth;
00660    if (options & kFixedHeight) size.fHeight = msize.fHeight;
00661    return size;
00662 }
00663 
00664 // ________________________________________________________________________
00665 void TGTableLayoutHints::SavePrimitive(ostream &out, Option_t * /*= ""*/)
00666 {
00667 
00668    // Save table layout hints as a C++ statement(s) on output stream out.
00669 
00670    TString hints;
00671    UInt_t pad = GetPadLeft()+GetPadRight()+GetPadTop()+GetPadBottom();
00672 
00673    if (!GetLayoutHints()) return;
00674 
00675    if ((fLayoutHints == kLHintsNormal) && (pad == 0)) return;
00676 
00677    if (fLayoutHints & kLHintsLeft) {
00678       if (hints.Length() == 0) hints  = "kLHintsLeft";
00679       else                     hints += " | kLHintsLeft";
00680    }
00681    if (fLayoutHints & kLHintsCenterX) {
00682       if  (hints.Length() == 0) hints  = "kLHintsCenterX";
00683       else                     hints += " | kLHintsCenterX";
00684    }
00685    if (fLayoutHints & kLHintsRight) {
00686       if (hints.Length() == 0) hints  = "kLHintsRight";
00687       else                     hints += " | kLHintsRight";
00688    }
00689    if (fLayoutHints & kLHintsTop) {
00690       if (hints.Length() == 0) hints  = "kLHintsTop";
00691       else                     hints += " | kLHintsTop";
00692    }
00693    if (fLayoutHints & kLHintsCenterY) {
00694       if (hints.Length() == 0) hints  = "kLHintsCenterY";
00695       else                     hints += " | kLHintsCenterY";
00696    }
00697    if (fLayoutHints & kLHintsBottom) {
00698       if (hints.Length() == 0) hints  = "kLHintsBottom";
00699       else                     hints += " | kLHintsBottom";
00700    }
00701    if (fLayoutHints & kLHintsExpandX) {
00702       if (hints.Length() == 0) hints  = "kLHintsExpandX";
00703       else                     hints += " | kLHintsExpandX";
00704    }
00705    if (fLayoutHints & kLHintsExpandY) {
00706       if (hints.Length() == 0) hints  = "kLHintsExpandY";
00707       else                     hints += " | kLHintsExpandY";
00708    }
00709    if (fLayoutHints & kLHintsShrinkX) {
00710       if (hints.Length() == 0) hints  = "kLHintsShrinkX";
00711       else                     hints += " | kLHintsShrinkX";
00712    }
00713    if (fLayoutHints & kLHintsShrinkY) {
00714       if (hints.Length() == 0) hints  = "kLHintsShrinkY";
00715       else                     hints += " | kLHintsShrinkY";
00716    }
00717    if (fLayoutHints & kLHintsFillX) {
00718       if (hints.Length() == 0) hints  = "kLHintsFillX";
00719       else                     hints += " | kLHintsFillX";
00720    }
00721    if (fLayoutHints & kLHintsFillY) {
00722       if (hints.Length() == 0) hints  = "kLHintsFillY";
00723       else                     hints += " | kLHintsFillY";
00724    }
00725    out << ", new TGTableLayoutHints(" << GetAttachLeft() << "," << GetAttachRight()
00726        << "," << GetAttachTop()  << "," << GetAttachBottom()
00727        << "," << hints;
00728 
00729    if (pad) {
00730       out << "," << GetPadLeft() << "," << GetPadRight()
00731           << "," << GetPadTop()  << "," << GetPadBottom();
00732    }
00733    out << ")";
00734 }
00735 
00736 // __________________________________________________________________________
00737 void TGTableLayout::SavePrimitive(ostream &out, Option_t * /*= ""*/)
00738 {
00739 
00740    // Save table layout as a C++ statement(s) on output stream.
00741 
00742    out << " new TGTableLayout(" << fMain->GetName() << "," << fNrows << "," << fNcols;
00743 
00744    if (fSep) {
00745       if (fHomogeneous == kTRUE)
00746          out << ", kTRUE";
00747       else
00748          out << ", kFALSE";
00749    out << fSep;
00750    }
00751    out  << ")";
00752    // hints parameter is not used/saved currently
00753 
00754 }

Generated on Tue Jul 5 14:22:04 2011 for ROOT_528-00b_version by  doxygen 1.5.1