TGTable.cxx

Go to the documentation of this file.
00001 // Author: Roel Aaij 21/07/2007
00002 
00003 /*************************************************************************
00004  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00009  *************************************************************************/
00010 
00011 #include "TGCanvas.h"
00012 #include "TGFrame.h"
00013 #include "TClass.h"
00014 #include "TGWindow.h"
00015 #include "TGResourcePool.h"
00016 #include "Riostream.h"
00017 #include "TSystem.h"
00018 #include "TImage.h"
00019 #include "TEnv.h"
00020 #include "TGToolTip.h"
00021 #include "TGWidget.h"
00022 #include "TGPicture.h"
00023 #include "TRandom3.h"
00024 #include "TVirtualTableInterface.h"
00025 #include "TGTable.h"
00026 #include "TGTableCell.h"
00027 #include "TGTableHeader.h"
00028 #include "TObjArray.h"
00029 #include "TGTableContainer.h"
00030 #include "TGScrollBar.h"
00031 #include "TGButton.h"
00032 #include "TGNumberEntry.h"
00033 #include "TGTextEntry.h"
00034 #include "TGLabel.h"
00035 #include "TColor.h"
00036 
00037 ClassImp(TGTable)
00038 ClassImp(TTableRange)
00039 
00040 //______________________________________________________________________________
00041 /* Begin_Html
00042 <center><h2>TGTable</h2></center>
00043 <br><br>                                                                    
00044 TGTable implements a table widget to display data in rows and       
00045 columns. The data is supplied by a TVirtualTableInterface.          
00046 <br><br>
00047 The table is a TGCanvas to make use of already available viewport   
00048 functionality and drawing optimizations.                            
00049 <br><br>
00050 The top left cell in a table has coordinates (0,0)                  
00051 <br><br>
00052 A TObjArray is used internally to ensure little overhead and fast   
00053 acces to cells.                                                     
00054 <br><br>
00055 If the data source has more rows than the default 50 rows of cells in
00056 memory, buttons at the bottom of the table can be used to load the
00057 next or previous chunk of data.
00058 <br><br>
00059 At the top of the table, a frame is visible that shows the coordinates
00060 of the top left cell currently in memmory in row,column. The amount of
00061 rows and columns is also shown in rows x columns. These values can be
00062 edited to move to a different area of the data source or to resize the
00063 table. Tab will switch between the enties, return will move to the
00064 currently entered range and resize the table if needed. Clicking the
00065 goto button has the same effect.
00066 <br><br>
00067 A TGTable is created by first creating an appropriate               
00068 TVirtualTableInterface from the data that needs visualization and   
00069 then creating the TGTable using this interface.                     
00070 <br><br>
00071 A simple macro to use a TGTable with a TGSimpleTableInterface:
00072 End_Html
00073 Begin_Macro(source, gui)
00074 {
00075    // Create an array to hold a bunch of numbers
00076    Int_t i = 0, j = 0;
00077    UInt_t nrows = 6, ncolumns = 5;
00078    Double_t** data = new Double_t*[nrows];
00079    for (i = 0; i < nrows; i++) {
00080       data[i] = new Double_t[ncolumns];
00081       for (j = 0; j < ncolumns; j++) {
00082          data[i][j] = 10 * i + j;
00083       }
00084    }
00085 
00086    // Create a main frame to contain the table
00087    TGMainFrame* mainframe = new TGMainFrame(0, 400, 200);
00088    mainframe->SetCleanup(kDeepCleanup) ;
00089 
00090    // Create an interface
00091    TGSimpleTableInterface *iface = new TGSimpleTableInterface(data, 6, 5); 
00092 
00093    // Create the table
00094    TGTable *table = new TGTable(mainframe, 999, iface); 
00095 
00096    // Add the table to the main frame
00097    mainframe->AddFrame(table, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00098 
00099    //Update data
00100    data[5][1] = 3.01; 
00101    //update the table view
00102    table->Update(); 
00103 
00104    // Layout and map the main frame
00105    mainframe->SetWindowName("Tree Table Test") ;
00106    mainframe->MapSubwindows() ;
00107    mainframe->Layout();
00108    mainframe->Resize() ;
00109    mainframe->MapWindow() ;
00110 
00111    return mainframe;
00112 }
00113 End_Macro
00114 Begin_Html
00115 
00116 It is also possible to visualise data from a tree. A simple macro
00117 showing the use of a TTreeTableInterface follows.
00118 End_Html
00119 Begin_Macro(source, gui)
00120 {
00121    // Open a root file.
00122    TFile *file = new TFile("$ROOTSYS/tutorials/hsimple.root");
00123    // Load a tree from the file
00124    TNtuple *ntuple = (TNtuple *)file.Get("ntuple");
00125 
00126    // Create an interface
00127    TTreeTableInterface *iface = new TTreeTableInterface(ntuple); 
00128 
00129    // Create a main frame to contain the table
00130    TGMainFrame* mainframe = new TGMainFrame(0, 400, 200);
00131    mainframe->SetCleanup(kDeepCleanup) ;
00132 
00133    // Create the table
00134    TGTable *table = new TGTable(mainframe, 999, iface, 10, 6); 
00135 
00136    // Add the table to the main frame
00137    mainframe->AddFrame(table, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00138 
00139    // Set a selection
00140    iface->SetSelection("px > 0.");
00141    // Add a column
00142    iface->AddColumn("(px+py)/(px-py)", 0);
00143    //update the table view
00144    table->Update(); 
00145 
00146    // Layout and map the main frame
00147    mainframe->SetWindowName("Tree Table Test") ;
00148    mainframe->MapSubwindows() ;
00149    mainframe->Layout();
00150    mainframe->Resize() ;
00151    mainframe->MapWindow() ;
00152 
00153    return mainframe;
00154 }
00155 End_Macro
00156 */
00157 
00158 // const TGGC *TGTable::fgDefaultSelectGC = 0;
00159 // const TGGC *TGTable::fgDefaultBckgndGC = 0;
00160 // const Int_t TGTable::fgDefaultTMode = kTextLeft | kTextTop;
00161 
00162 // TList *TGTable::fgEditList = 0 ;
00163 
00164 //______________________________________________________________________________
00165 TGTable::TGTable(const TGWindow *p, Int_t id, TVirtualTableInterface *interface, 
00166                  UInt_t nrows, UInt_t ncolumns) 
00167    : TGCompositeFrame(p, 500, 500, kVerticalFrame), TGWidget(id), fRows(0), 
00168      fRowHeaders(0), fColumnHeaders(0), fReadOnly(kFALSE), fSelectColor(0), 
00169      fTMode(0), fAllData(kFALSE), fTableFrame(0), fCanvas(0), fCellWidth(80), 
00170      fCellHeight(25), fInterface(interface)
00171 {
00172    // TGTable constuctor.
00173 
00174    fCurrentRange = new TTableRange();
00175    fDataRange = new TTableRange();
00176    fGotoRange = new TTableRange();
00177    TGLayoutHints *hints = 0;
00178    fCellHintsList = new TList(hints);
00179    fRHdrHintsList = new TList(hints);
00180    fCHdrHintsList = new TList(hints);
00181    fMainHintsList = new TList(hints);
00182 
00183    // To be done: GetBackground colors for .rootrc 
00184    SetBackgroundColor(GetWhitePixel());
00185    fEvenRowBackground = TColor::RGB2Pixel(204, 255, 204);
00186    fOddRowBackground  = TColor::RGB2Pixel(255, 255, 255);
00187    fHeaderBackground  = TColor::RGB2Pixel(204, 204, 255);
00188 
00189    fCurrentRange->fXbr = ncolumns;
00190    fCurrentRange->fYbr = nrows;
00191 
00192    Init();
00193 
00194    if(fInterface) SetInterface(fInterface, nrows, ncolumns);
00195    SetWindowName();
00196 //    MapWindow();
00197 }
00198 
00199 //______________________________________________________________________________
00200 TGTable::~TGTable()
00201 {
00202    // TGTable destructor.
00203 
00204    // delete all cells in a good way
00205    UInt_t i = 0, j = 0;
00206    for (i = 0; i < GetNTableRows(); i++) {
00207       for (j = 0; j < GetNTableColumns(); j++) {
00208          delete GetCell(i,j);
00209       }
00210       delete fRows->At(i);
00211    }
00212    delete fRows;
00213    delete fRowHeaders;
00214    delete fColumnHeaders;
00215 
00216    delete fCurrentRange;
00217    delete fDataRange;
00218    delete fGotoRange;
00219 
00220    fCellHintsList->Delete();
00221    delete fCellHintsList;
00222    delete fRHdrHintsList;
00223    delete fCHdrHintsList;
00224 
00225    fMainHintsList->Delete();
00226    delete fMainHintsList;
00227 }
00228 
00229 //______________________________________________________________________________
00230 void TGTable::Init() 
00231 {
00232    // Initialise the TGTable.
00233 
00234    UInt_t nrows = GetNTableRows();
00235    UInt_t ncolumns = GetNTableColumns();
00236 
00237    // Main layout frames
00238    fTopFrame = new TGHorizontalFrame(this, fWidth, fCellHeight);
00239    fTopExtraFrame = new TGHorizontalFrame(fTopFrame, fWidth - fCellWidth, 
00240                                           fCellHeight);
00241    TGString *str = new TGString();
00242    *str += GetNTableRows();
00243    *str += "x";
00244    *str += GetNTableColumns();
00245    *str += " Table";
00246    fTableHeader = new TGTableHeader(fTopFrame, this, str, 0, 
00247                                     kTableHeader);
00248 
00249    fBottomFrame = new TGHorizontalFrame(this, fWidth, fHeight - fCellHeight);
00250    fRHdrFrame = new TGTableHeaderFrame(fBottomFrame, this, fCellWidth, 
00251                                        fHeight - fCellHeight, kRowHeader);
00252    fCHdrFrame = new TGTableHeaderFrame(fTopExtraFrame, this, fWidth - fCellWidth, 
00253                                        fCellHeight, kColumnHeader);
00254 
00255    // Frame for the buttons at the bottom
00256    fButtonFrame = new TGHorizontalFrame(this, 200, 50);
00257    fNextButton = new TGTextButton(fButtonFrame, "Next", WidgetId() + 2000); 
00258    fPrevButton = new TGTextButton(fButtonFrame, "Previous", WidgetId() + 2001); 
00259    fUpdateButton = new TGTextButton(fButtonFrame, "Update", WidgetId() + 2002); 
00260 
00261    fCanvas = new TGCanvas(fBottomFrame, ncolumns * fCellWidth, 
00262                           nrows * fCellHeight, 0);
00263    fTableFrame = new TGTableFrame(fCanvas->GetViewPort(), nrows, ncolumns);
00264    fTableFrame->SetCanvas(fCanvas);
00265    fCanvas->SetContainer(fTableFrame->GetFrame());
00266 
00267    // Frame to display range info and goto button.
00268    fRangeFrame = new TGHorizontalFrame(this, 450, 50);
00269    fFirstCellLabel = new TGLabel(fRangeFrame, "Top left cell in range:");
00270    fRangeLabel = new TGLabel(fRangeFrame, "Range:");
00271    fFirstCellEntry = new TGTextEntry(fRangeFrame, "0,0", WidgetId() + 2050);
00272    fFirstCellEntry->SetWidth(100);
00273    fFirstCellEntry->SetAlignment(kTextRight);
00274    fFirstCellEntry->Connect("TextChanged(const char *)", "TGTable", this, 
00275                             "UserRangeChange()");
00276    fFirstCellEntry->Connect("ReturnPressed()", "TGTable", this, "Goto()");
00277 
00278    TString range;
00279    range += GetNTableRows();
00280    range += "x";
00281    range += GetNTableColumns();
00282    fRangeEntry = new TGTextEntry(range, fRangeFrame, WidgetId() + 2051);
00283    fRangeEntry->SetWidth(100);
00284    fRangeEntry->SetAlignment(kTextRight);
00285    fRangeEntry->Connect("TextChanged(const char *)", "TGTable", this,
00286                         "UserRangeChange()");
00287    fRangeEntry->Connect("ReturnPressed()", "TGTable", this, "Goto()");
00288    fRangeEntry->Connect("TabPressed()", "TGTextEntry", fFirstCellEntry, 
00289                             "SetFocus()");
00290    fFirstCellEntry->Connect("TabPressed()", "TGTextEntry", fRangeEntry, 
00291                             "SetFocus()");
00292 
00293    fGotoRange->fXbr = GetNTableRows();
00294    fGotoRange->fYbr = GetNTableColumns();
00295    fGotoButton = new TGTextButton(fRangeFrame, "Goto", WidgetId() + 2003); 
00296    fGotoButton->SetState(kButtonDisabled);
00297    
00298    // Set frame backgrounds
00299    fCHdrFrame->SetBackgroundColor(fBackground);
00300    fRHdrFrame->SetBackgroundColor(fBackground);
00301    fRangeFrame->SetBackgroundColor(fBackground);
00302    fTopFrame->SetBackgroundColor(fBackground);
00303    fTopExtraFrame->SetBackgroundColor(fBackground);
00304    fBottomFrame->SetBackgroundColor(fBackground);
00305    fButtonFrame->SetBackgroundColor(fBackground);
00306    fFirstCellLabel->SetBackgroundColor(fBackground);
00307    fRangeLabel->SetBackgroundColor(fBackground);
00308 
00309    // Create the cells needed
00310    UInt_t i = 0, j = 0;
00311    TGString *label = 0;
00312    fRowHeaders = new TObjArray(nrows);
00313    for(i = 0; i < nrows; i++) {
00314       TGTableHeader *hdr = new TGTableHeader(fRHdrFrame, this, 
00315                                              label, i, kRowHeader); 
00316       fRowHeaders->AddAt(hdr, i);
00317    }
00318    fColumnHeaders = new TObjArray(ncolumns);
00319    for(i = 0; i < ncolumns; i++) {
00320       TGTableHeader *hdr = new TGTableHeader(fCHdrFrame, this, 
00321                                              label, i, kColumnHeader);
00322       fColumnHeaders->AddAt(hdr, i);
00323    }
00324 
00325    TGTableCell *cell = 0;
00326    TObjArray *row = 0;
00327    fRows = new TObjArray(nrows);
00328    for (i = 0; i < nrows; i++) {
00329       row = new TObjArray(ncolumns);
00330       fRows->AddAt(row, i);
00331       for (j = 0; j < ncolumns; j++) {
00332          cell = new TGTableCell(fCanvas->GetContainer(), this, label, i, j);
00333          row->AddAt(cell, j);
00334       }
00335    }
00336 
00337    // Check if the table covers all the data
00338    if ((GetNDataColumns() >= GetNTableColumns()) && 
00339        (GetNDataRows() >= GetNTableRows())) {
00340       fAllData = kTRUE;
00341    } else {
00342       fAllData = kFALSE;
00343    }
00344 
00345    TGLayoutHints *lhints = 0;
00346 
00347    // Add cells and headers to layout frames
00348    for (i = 0; i < nrows; i++) {
00349       lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
00350       fRHdrHintsList->Add(lhints);
00351       fRHdrFrame->AddFrame(GetRowHeader(i), lhints);
00352       for (j = 0; j < ncolumns; j++) {
00353          if (i == 0) {
00354             lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
00355             fCHdrHintsList->Add(lhints);
00356             fCHdrFrame->AddFrame(GetColumnHeader(j), lhints);
00357          }
00358          lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
00359          fCellHintsList->Add(lhints);
00360          fCanvas->AddFrame(GetCell(i,j), lhints);
00361       }
00362    }
00363    
00364    // Add frames to the range frame
00365    lhints = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 3, 30, 4, 4);
00366    fRangeFrame->AddFrame(fGotoButton, lhints);
00367    lhints = new TGLayoutHints(kLHintsRight |kLHintsCenterY, 3, 3, 4, 4);
00368    fRangeFrame->AddFrame(fRangeEntry, lhints);
00369    lhints = new TGLayoutHints(kLHintsRight |kLHintsCenterY, 3, 3, 4, 4);
00370    fRangeFrame->AddFrame(fRangeLabel, lhints);
00371    lhints = new TGLayoutHints(kLHintsRight |kLHintsCenterY, 3, 3, 4, 4);
00372    fRangeFrame->AddFrame(fFirstCellEntry, lhints);
00373    lhints = new TGLayoutHints(kLHintsRight |kLHintsCenterY, 3, 3, 4, 4);
00374    fRangeFrame->AddFrame(fFirstCellLabel, lhints);
00375    lhints = new TGLayoutHints(kLHintsRight |kLHintsTop);
00376    fRangeFrame->Resize();
00377    // Range frame size = 448
00378    AddFrame(fRangeFrame, lhints);
00379 
00380    // Add table to the main composite frame
00381    lhints = new TGLayoutHints(kLHintsLeft |kLHintsTop);
00382    fTopFrame->AddFrame(fTableHeader, lhints);
00383    lhints = new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsTop);
00384    fTopExtraFrame->AddFrame(fCHdrFrame, lhints);
00385    lhints = new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsTop);
00386    fTopFrame->AddFrame(fTopExtraFrame, lhints);
00387    lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY);
00388    fBottomFrame->AddFrame(fRHdrFrame, lhints);
00389    lhints =  new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX 
00390                                | kLHintsExpandY);
00391    fBottomFrame->AddFrame(fCanvas, lhints);
00392 
00393    // Add buttons to button frame
00394    lhints = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 3, 30, 4, 4);
00395    fButtonFrame->AddFrame(fNextButton, lhints);   
00396    lhints = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 3, 3, 4, 4);
00397    fButtonFrame->AddFrame(fPrevButton, lhints);   
00398    lhints = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 3, 30, 4, 4);
00399    fButtonFrame->AddFrame(fUpdateButton, lhints);
00400    fButtonFrame->Resize();
00401    fButtonFrame->ChangeOptions(fButtonFrame->GetOptions() | kFixedWidth);
00402 
00403    lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX);
00404    AddFrame(fTopFrame, lhints);
00405    lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | 
00406                               kLHintsExpandY);
00407    AddFrame(fBottomFrame, lhints);
00408    lhints = new TGLayoutHints(kLHintsExpandX | kLHintsTop);
00409    AddFrame(fButtonFrame, lhints);
00410 
00411    // Setup scrolling for the headers
00412    TGScrollBar *sbar= fCanvas->GetVScrollbar();
00413    sbar->Connect("PositionChanged(Int_t)", "TGTable", this, "ScrollRHeaders(Int_t)");
00414    sbar = fCanvas->GetHScrollbar();
00415    sbar->Connect("PositionChanged(Int_t)", "TGTable", this, "ScrollCHeaders(Int_t)");
00416 
00417    // Connections for buttons
00418    fUpdateButton->Connect("Clicked()", "TGTable", this, "Update()");
00419    fNextButton->Connect("Clicked()", "TGTable", this, "NextChunk()");
00420    fPrevButton->Connect("Clicked()", "TGTable", this, "PreviousChunk()");
00421    fGotoButton->Connect("Clicked()", "TGTable", this, "Goto()");
00422 
00423 //    MapSubwindows();
00424 //    Layout();
00425 }
00426 
00427 //______________________________________________________________________________
00428 void TGTable::DoRedraw()
00429 {
00430    // Redraw the TGTable.
00431 
00432    MapSubwindows();
00433    Layout();
00434 }
00435 
00436 //______________________________________________________________________________
00437 void TGTable::Expand(UInt_t nrows, UInt_t ncolumns) 
00438 {
00439    // Expand a TGTable by nrows and ncolumns.
00440 
00441    ExpandRows(nrows);
00442    ExpandColumns(ncolumns);
00443 }
00444 
00445 //______________________________________________________________________________
00446 void TGTable::ExpandColumns(UInt_t ncolumns) 
00447 {
00448    // Expand the columns of a TGTable by ncolumns.
00449 
00450    UInt_t i = 0, j = 0;
00451    TGString *label = 0;
00452 
00453    UInt_t ntrows = GetNTableRows();
00454    UInt_t ntcolumns = GetNTableColumns();
00455 
00456    fColumnHeaders->Expand(ntcolumns + ncolumns);
00457 
00458    for (i = 0; i < ncolumns; i++) {
00459       TGTableHeader *header = new TGTableHeader(fCHdrFrame, this, label, 
00460                                                 ntcolumns + i, 
00461                                                 kColumnHeader);
00462       fColumnHeaders->AddAt(header, ntcolumns + i);
00463    }
00464 
00465    for (i = 0; i < ntrows; i++) {
00466       GetRow(i)->Expand(ntcolumns + ncolumns);
00467       for (j = 0; j < ncolumns; j++) {
00468          TGTableCell *cell = new TGTableCell(fCanvas->GetContainer(), this, label, i, 
00469                                              ntcolumns + j);
00470          GetRow(i)->AddAt(cell, ntcolumns + j);
00471       }
00472    }
00473 
00474    fCurrentRange->fXbr += ncolumns;
00475 
00476    if ((GetNDataColumns() == GetNTableColumns()) && 
00477        (GetNDataRows() == GetNTableRows())) {
00478       fAllData = kTRUE;
00479    } else {
00480       fAllData = kFALSE;
00481    }
00482 }
00483 
00484 //______________________________________________________________________________
00485 void TGTable::ExpandRows(UInt_t nrows) 
00486 {
00487    // Expand the rows of a TGTable by nrows.
00488 
00489    UInt_t i = 0, j = 0; 
00490 
00491    UInt_t ntrows = GetNTableRows();
00492    UInt_t ntcolumns = GetNTableColumns();
00493 
00494    fRows->Expand(ntrows + nrows);
00495    fRowHeaders->Expand(ntrows + nrows);
00496    for (i = 0; i < nrows; i++) {
00497       TObjArray *row = new TObjArray(ntcolumns);
00498       fRows->AddAt(row, ntrows + i);  
00499       TGString *label = 0;
00500       TGTableHeader *header = new TGTableHeader(fRHdrFrame, this, label, 
00501                                                 ntrows + i, kRowHeader);
00502       fRowHeaders->AddAt(header, ntrows + i);
00503       for (j = 0; j < ntcolumns ; j++) {
00504          TGTableCell *cell = new TGTableCell(fCanvas->GetContainer(), this, label, 
00505                                              ntrows + i, j);
00506          GetRow(ntrows + i)->AddAt(cell, j);
00507       }
00508    }
00509    
00510    fCurrentRange->fYbr += nrows;
00511 
00512    if ((GetNDataColumns() == GetNTableColumns()) && 
00513        (GetNDataRows() == GetNTableRows())) {
00514       fAllData = kTRUE;
00515    } else {
00516       fAllData = kFALSE;
00517    }
00518 }
00519 
00520 //______________________________________________________________________________
00521 UInt_t TGTable::GetCHdrWidth() const
00522 {
00523    // Get the current width of the column header frame.
00524 
00525    Int_t ncolumns = GetNTableColumns();
00526    UInt_t width = 0;
00527    for (Int_t i = 0; i < ncolumns; i++) {
00528       width += GetColumnHeader(i)->GetWidth();
00529    }
00530    return width;
00531 }
00532 
00533 //______________________________________________________________________________
00534 UInt_t TGTable::GetRHdrHeight() const
00535 {
00536    // Get the current height of the row header frame.
00537 
00538    Int_t nrows = GetNTableRows();
00539    UInt_t height = 0;
00540    for (Int_t i = 0; i < nrows; i++) {
00541       height += GetRowHeader(i)->GetHeight();
00542    }
00543    return height;
00544 }
00545 
00546 //______________________________________________________________________________
00547 void TGTable::Shrink(UInt_t nrows, UInt_t ncolumns) 
00548 {
00549    // Shrink the TGTable by nrows and ncolumns.
00550 
00551    ShrinkRows(nrows);
00552    ShrinkColumns(ncolumns);
00553 }
00554 
00555 //______________________________________________________________________________
00556 void TGTable::ShrinkColumns(UInt_t ncolumns) 
00557 {
00558    // Shrink the columns of the TGTable by ncolumns.
00559 
00560    UInt_t i = 0, j = 0, k = 0;
00561 
00562    if(GetNTableColumns() - ncolumns < 1) {
00563       Info("TGTable::ShrinkColumns", "Cannot shrink smaller than 1"
00564                                      " column, adjusting");
00565       ncolumns = GetNTableColumns() - 1;
00566    }
00567 
00568    UInt_t ntrows = GetNTableRows();
00569    UInt_t ntcolumns = GetNTableColumns();
00570 
00571    TGTableCell *cell = 0;
00572 
00573    //Destroy windows
00574 
00575    for (i = 0; i < ntrows; i++) {
00576       for (j = 0; j < ncolumns; j++) {
00577          k = ntcolumns - ncolumns + j;
00578          cell = (TGTableCell *)GetRow(i)->RemoveAt(k);
00579          cell->DestroyWindow();
00580          delete cell;
00581       }
00582       GetRow(i)->Expand(ntcolumns - ncolumns);
00583    }
00584 
00585    TGTableHeader *hdr = 0;
00586    for (j = 0; j < ncolumns; j++) {
00587       hdr = (TGTableHeader *)fColumnHeaders->RemoveAt(ntcolumns - ncolumns + j);
00588       hdr->DestroyWindow();
00589       delete hdr;
00590    }
00591    fColumnHeaders->Expand(ntcolumns - ncolumns);
00592 
00593    fCurrentRange->fXbr -= ncolumns;
00594 
00595 
00596    if ((GetNDataColumns() == GetNTableColumns()) && 
00597        (GetNDataRows() == GetNTableRows())) {
00598       fAllData = kTRUE;
00599    } else {
00600       fAllData = kFALSE;
00601    }
00602 }
00603 
00604 //______________________________________________________________________________
00605 void TGTable::ShrinkRows(UInt_t nrows) 
00606 {
00607    // Shrink the rows of the TGTable by nrows.
00608 
00609    UInt_t i = 0 , j = 0;
00610 
00611    if(GetNTableRows() - nrows < 1) {
00612       Info("TGTable::ShrinkRows", "Cannot shrink smaller than 1 row, adjusting");
00613       nrows = GetNTableRows() - 1;
00614    }
00615 
00616    UInt_t ntrows = GetNTableRows();
00617    UInt_t ntcolumns = GetNTableColumns();
00618 
00619    TObjArray *row = 0;
00620    TGTableCell *cell = 0;
00621    TGTableHeader *hdr = 0;
00622 
00623    for (i = 0; i < nrows; i++) {
00624       for (j = 0; j < ntcolumns ; j++) {
00625          cell = (TGTableCell *)GetRow(ntrows - nrows + i)->RemoveAt(j);
00626          cell->DestroyWindow();
00627          delete cell;
00628       }
00629       row = (TObjArray *)fRows->RemoveAt(ntrows - nrows + i);
00630       delete row;
00631       hdr = (TGTableHeader *)fRowHeaders->RemoveAt(ntrows - nrows + i);
00632       hdr->DestroyWindow();
00633       delete hdr;
00634    }
00635    fRows->Expand(ntrows - nrows);
00636    fRowHeaders->Expand(ntrows - nrows);
00637 
00638    fCurrentRange->fYbr -= nrows;
00639 
00640    if ((GetNDataColumns() == GetNTableColumns()) && 
00641        (GetNDataRows() == GetNTableRows())) {
00642       fAllData = kTRUE;
00643    } else {
00644       fAllData = kFALSE;
00645    }
00646 }
00647 
00648 //______________________________________________________________________________
00649 void TGTable::UpdateHeaders(EHeaderType type)
00650 {
00651    // Update the labels of the headers of the given type
00652 
00653    UInt_t max = 0, i = 0, d = 0;
00654    if(type == kColumnHeader) {
00655       max = GetNTableColumns();
00656       for (i = 0; i < max; i++) {
00657          d = fCurrentRange->fXtl + i;
00658          GetColumnHeader(i)->SetLabel(fInterface->GetColumnHeader(d));
00659       }
00660    } else if (type == kRowHeader) {
00661       max = GetNTableRows();
00662       for (i = 0; i < max; i++) {
00663          d = fCurrentRange->fYtl + i;
00664          GetRowHeader(i)->SetLabel(fInterface->GetRowHeader(d));
00665       }
00666    }
00667 }
00668 
00669 //______________________________________________________________________________
00670 void TGTable::SetInterface(TVirtualTableInterface *interface, 
00671                            UInt_t nrows, UInt_t ncolumns)
00672 {
00673    // Set the interface that the TGTable uses to interface.
00674 
00675    fInterface = interface;
00676 
00677    // Set up ranges
00678 
00679    fDataRange->fXtl = 0;
00680    fDataRange->fYtl = 0;
00681    fDataRange->fXbr = fInterface->GetNColumns();
00682    fDataRange->fYbr = fInterface->GetNRows();
00683 
00684    UInt_t x = 0, y = 0;
00685    if (fDataRange->fXbr < ncolumns) {
00686       x = fDataRange->fXbr;
00687    } else {
00688       x = ncolumns;
00689    }
00690 
00691    if (fDataRange->fYbr < nrows) {
00692       y = fDataRange->fYbr;
00693    } else {
00694       y = nrows;
00695    }
00696 
00697    GotoTableRange(0, 0, x, y);
00698 
00699    if ((GetNDataColumns() == GetNTableColumns()) && 
00700        (GetNDataRows() == GetNTableRows())) {
00701       fAllData = kTRUE;
00702    } else {
00703       fAllData = kFALSE;
00704    }
00705 }
00706 
00707 //______________________________________________________________________________
00708 void TGTable::ResizeTable(UInt_t newnrows, UInt_t newncolumns)
00709 {
00710    // Resize the table to newnrows and newncolumns and add all the frames to 
00711    // their parent frames.
00712 
00713    UInt_t oldnrows = GetNTableRows();
00714    UInt_t oldncolumns = GetNTableColumns();
00715 
00716    UInt_t oldwidth = 0, oldheight = 0;
00717    Int_t i = 0, j = 0;
00718 
00719    oldwidth = GetCHdrWidth();
00720    oldheight = GetRHdrHeight();
00721 
00722    TGCompositeFrame *container = (TGCompositeFrame *)fCanvas->GetContainer();
00723 
00724    if (newnrows != oldnrows){
00725       if (newnrows > oldnrows) {
00726          ExpandRows(newnrows - oldnrows);
00727       } else {
00728          ShrinkRows(oldnrows - newnrows);
00729       }
00730    }
00731 
00732    if (newncolumns != oldncolumns){
00733       if (newncolumns > oldncolumns) {
00734          ExpandColumns(newncolumns - oldncolumns);
00735       } else {
00736          ShrinkColumns(oldncolumns - newncolumns);
00737       }
00738    }
00739 
00740    // Update the layoutmanager and add the frames.   
00741    if ((newncolumns != oldncolumns) || (newnrows != oldnrows)) {      
00742       container->RemoveAll();
00743       fCellHintsList->Delete();
00744 
00745       fRHdrFrame->RemoveAll();
00746       fRHdrHintsList->Delete();
00747 
00748       fCHdrFrame->RemoveAll();
00749       fCHdrHintsList->Delete();
00750 
00751       container->SetLayoutManager(new TGMatrixLayout(container, 
00752                                                      newnrows, newncolumns));
00753       // Add frames to layout frames
00754       TGLayoutHints *lhints = 0;
00755       for (i = 0; i < (Int_t)newnrows; i++) {
00756          lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
00757          fRHdrHintsList->Add(lhints);
00758          fRHdrFrame->AddFrame(GetRowHeader(i), lhints);
00759          for (j = 0; j < (Int_t)newncolumns; j++) {
00760             if (i == 0) {
00761                lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
00762                fCHdrHintsList->Add(lhints);
00763                fCHdrFrame->AddFrame(GetColumnHeader(j), lhints);
00764             }
00765             lhints = new TGLayoutHints(kLHintsLeft | kLHintsTop);
00766             fCellHintsList->Add(lhints);
00767             fCanvas->AddFrame(GetCell(i,j), lhints);
00768          }
00769       }
00770    }
00771    fCanvas->MapSubwindows();
00772    fCanvas->Layout();
00773 }
00774 
00775 //______________________________________________________________________________
00776 void TGTable::UpdateRangeFrame()
00777 {
00778    // Update the range shown in the range frame.
00779 
00780    TString tl, range;
00781    
00782    tl += fCurrentRange->fYtl;
00783    tl += ",";
00784    tl += fCurrentRange->fXtl;
00785    fFirstCellEntry->SetText(tl.Data());
00786 
00787    range += GetNTableRows();
00788    range += "x";
00789    range += GetNTableColumns();
00790    fRangeEntry->SetText(range.Data());
00791 
00792    fGotoButton->SetState(kButtonDisabled);
00793 }
00794 
00795 //______________________________________________________________________________
00796 TObjArray *TGTable::GetRow(UInt_t row)
00797 {
00798    // Get row. NOTE: Do not delete the TObjArray returned or the cells
00799    // it contains, they are owned by the TGTable.
00800 
00801    return (TObjArray *)fRows->At(row);
00802 }
00803 
00804 //______________________________________________________________________________
00805 TObjArray *TGTable::GetColumn(UInt_t column)
00806 {
00807    // Return a pointer to a TObjArray that contains pointers to all
00808    // the cells in column. NOTE: The user will have to delete the
00809    // TObjArray, but do NOT delete the cells it contains, they are
00810    // owned by the TGTable and will be deleted from the TGTable with
00811    // undefined consequenses.
00812 
00813    UInt_t nrows = GetNTableRows();
00814 
00815    TObjArray *col = new TObjArray(nrows);
00816    for(UInt_t ui = 0; ui < nrows; ui++) {
00817       col->AddAt(GetCell(ui, column), ui);
00818    }
00819    return col;
00820 }
00821 
00822 // //______________________________________________________________________________
00823 // void TGTable::Select(TGTableCell *celltl, TGTableCell *cellbr)
00824 // {
00825 // }
00826 
00827 // //______________________________________________________________________________
00828 // void TGTable::Select(UInt_t xcelltl, UInt_t ycelltl, UInt_t xcell2, UInt_t ycell2)
00829 // {
00830 // }
00831 
00832 // //______________________________________________________________________________
00833 // void TGTable::SelectAll()
00834 // {
00835 // }
00836 
00837 // //______________________________________________________________________________
00838 // void TGTable::SelectRow(TGTableCell *cell)
00839 // {
00840 // }
00841 
00842 // //______________________________________________________________________________
00843 // void TGTable::SelectRow(UInt_t row)
00844 // {
00845 // }
00846 
00847 // //______________________________________________________________________________
00848 // void TGTable::SelectRows(UInt_t row, UInt_t nrows)
00849 // {
00850 // }
00851 
00852 // //______________________________________________________________________________
00853 // void TGTable::SelectColumn(TGTableCell *cell)
00854 // {
00855 // }
00856 
00857 // //______________________________________________________________________________
00858 // void TGTable::SelectColumn(UInt_t column)
00859 // {
00860 // }
00861 
00862 // //______________________________________________________________________________
00863 // void TGTable::SelectColumns(UInt_t column, UInt_t ncolumns)
00864 // {
00865 // }
00866 
00867 // //______________________________________________________________________________
00868 // void TGTable::SetBckgndGC(TGGC *gc)
00869 // {
00870 // }
00871 
00872 // //______________________________________________________________________________
00873 // void TGTable::SetSelectGC(TGGC *gc)
00874 // {
00875 // }
00876 
00877 // //______________________________________________________________________________
00878 // void TGTable::SetTextJustify(Int_t tmode)
00879 // {
00880 // }
00881 
00882 //______________________________________________________________________________
00883 const TGTableCell* TGTable::GetCell(UInt_t i, UInt_t j) const
00884 {
00885    // Const version of GetCell().
00886 
00887    return const_cast<TGTable *>(this)->GetCell(i, j);
00888 }
00889 
00890 //______________________________________________________________________________
00891 TGTableCell* TGTable::GetCell(UInt_t i, UInt_t j)
00892 {
00893    // Return a pointer to the TGTableCell at position i,j.
00894 
00895    TObjArray *row = (TObjArray *)fRows->At(i);
00896    if(row) {
00897       TGTableCell *cell = (TGTableCell *)row->At(j);
00898       return cell;
00899    } else {
00900       return 0;
00901    }
00902 }
00903 
00904 //______________________________________________________________________________
00905 const TGTableCell* TGTable::FindCell(TGString label) const
00906 {
00907    // Const version of FindCell().
00908 
00909    return const_cast<TGTable *>(this)->FindCell(label);
00910 }
00911 
00912 //______________________________________________________________________________
00913 TGTableCell* TGTable::FindCell(TGString label)
00914 {
00915    // Find the TGTableCell with label.
00916 
00917    TObjArray *row = 0;
00918    TGTableCell *cell = 0;
00919    UInt_t i = 0, j = 0;
00920    //continue here
00921    UInt_t nrows = GetNTableRows();
00922    UInt_t ncolumns = GetNTableColumns();
00923    for (i = 0; i < nrows; i++) {
00924       for (j = 0; j < ncolumns; j++) {
00925          row = (TObjArray *)fRows->At(j);
00926          cell = (TGTableCell *)row->At(i);
00927          if (*(cell->GetLabel()) == label) {
00928             return cell;
00929          }
00930       }
00931    }
00932    return 0;
00933 }
00934 
00935 //______________________________________________________________________________
00936 void TGTable::Show()
00937 {
00938    // Show the contents of the TGTable in stdout.
00939 
00940    TGTableCell *cell = 0;
00941    TGTableHeader *hdr = 0;
00942    UInt_t i = 0, j = 0;
00943    UInt_t nrows = GetNTableRows();
00944    UInt_t ncolumns = GetNTableColumns();
00945 
00946    // save actual formatting flags
00947    std::ios_base::fmtflags org_flags = std::cout.flags();
00948 
00949    for (j = 0; j < ncolumns + 1; j++) {
00950       if (j == 0) {
00951          hdr = fTableHeader;
00952          if (hdr) std::cout << " " << setw(12) << right 
00953                             << hdr->GetLabel()->GetString() << " ";
00954       } else {
00955          hdr = GetColumnHeader(j - 1);
00956          if (hdr) std::cout << " " << setw(12) << right 
00957                             << hdr->GetLabel()->GetString() << " ";
00958       }
00959    }
00960    std::cout << std::endl;
00961 
00962    for (i = 0; i < nrows; i++) {
00963       for (j = 0; j < ncolumns + 1; j++) {
00964          if (j == 0) {
00965             hdr = GetRowHeader(i);
00966             if (hdr) std::cout << " " << setw(12) << right 
00967                                << hdr->GetLabel()->GetString() << " ";
00968          } else {
00969             cell = GetCell(i, j - 1);
00970             if (cell) std::cout << " " << setw(12) << right 
00971                                 << cell->GetLabel()->GetString() << " ";
00972          }
00973       }
00974       std::cout << std::endl;
00975    }
00976    // restore original formatting flags
00977    std::cout.flags(org_flags);
00978 }
00979 
00980 // //______________________________________________________________________________
00981 // void TGTable::InsertRowBefore(UInt_t row, UInt_t nrows)
00982 // {
00983 // }
00984 
00985 // //______________________________________________________________________________
00986 // void TGTable::InsertRowBefore(TGString label, UInt_t nrows)
00987 // {
00988 // }
00989 
00990 // //______________________________________________________________________________
00991 // void TGTable::InsertRowAfter(UInt_t row, UInt_t nrows)
00992 // {
00993 // }
00994 
00995 // //______________________________________________________________________________
00996 // void TGTable::InsertRowAfter(TGString label, UInt_t nrows)
00997 // {
00998 // }
00999 
01000 // //______________________________________________________________________________
01001 // void TGTable::InsertRowAt(UInt_t row, UInt_t nrows)
01002 // {
01003 // }
01004 
01005 // //______________________________________________________________________________
01006 // void TGTable::InsertRowAt(TGString label, UInt_t nrows)
01007 // {
01008 // }
01009 
01010 // //______________________________________________________________________________
01011 // void TGTable::InsertColumnBefore(UInt_t column, UInt_t ncolumns)
01012 // {
01013 // }
01014 
01015 // //______________________________________________________________________________
01016 // void TGTable::InsertColumnBefore(TGString label, UInt_t ncolumns)
01017 // {
01018 // }
01019 
01020 // //______________________________________________________________________________
01021 // void TGTable::InsertColumnAfter(UInt_t column, UInt_t ncolumns)
01022 // {
01023 // }
01024 
01025 // //______________________________________________________________________________
01026 // void TGTable::InsertColumnAfter(TGString label, UInt_t ncolumns)
01027 // {
01028 // }
01029 
01030 // //______________________________________________________________________________
01031 // void TGTable::InsertColumnAt(UInt_t column, UInt_t ncolumns)
01032 // {
01033 // }
01034 
01035 // //______________________________________________________________________________
01036 // void TGTable::InsertColumnAt(TGString label, UInt_t ncolumns)
01037 // {
01038 // }
01039 
01040 // //______________________________________________________________________________
01041 // void TGTable::RemoveRows(UInt_t row, UInt_t nrows)
01042 // {
01043 // }
01044 
01045 // //______________________________________________________________________________
01046 // void TGTable::RemoveColumns(UInt_t column, UInt_t ncolumns)
01047 // {
01048 // }
01049 
01050 //______________________________________________________________________________
01051 void TGTable::UpdateView() 
01052 {
01053    // Update and layout the visible part of the TGTable.
01054 
01055    UInt_t nrows = GetNTableRows();
01056    UInt_t ncolumns = GetNTableColumns();
01057 
01058    TGString *str = new TGString();
01059    *str += nrows;
01060    *str += "x";
01061    *str += ncolumns;
01062    *str += " Table";
01063    fTableHeader->SetLabel(str->GetString());
01064    delete str;
01065 
01066    UpdateHeaders(kRowHeader);
01067    UpdateHeaders(kColumnHeader);
01068 
01069    UInt_t i = 0, j = 0;
01070    UInt_t k = 0, l = 0;
01071 
01072    TGTableCell * cell = 0;
01073    for (i = 0; i < nrows; i++) {
01074       for (j = 0; j < ncolumns; j++) {
01075          cell = GetCell(i,j);
01076          k = fCurrentRange->fYtl + i;
01077          l = fCurrentRange->fXtl + j;
01078 
01079          const char *label = fInterface->GetValueAsString(k,l);
01080          if(cell) cell->SetLabel(label);
01081       }
01082    }
01083    
01084    MapSubwindows();
01085    Layout();
01086    gClient->NeedRedraw(fTableHeader);
01087    TGViewPort *vp = fCanvas->GetViewPort();
01088    fTableFrame->DrawRegion(0, 0, vp->GetWidth(), vp->GetHeight());
01089    fCHdrFrame->DrawRegion(0, 0, fCHdrFrame->GetWidth(), fCHdrFrame->GetHeight());
01090    fRHdrFrame->DrawRegion(0, 0, fRHdrFrame->GetWidth(), fRHdrFrame->GetHeight());
01091 
01092    UpdateRangeFrame();
01093 }
01094 
01095 //______________________________________________________________________________
01096 UInt_t TGTable::GetNTableRows() const
01097 {
01098    // Return the amount of rows in the table.
01099    
01100    return fCurrentRange->fYbr - fCurrentRange->fYtl;
01101 }
01102 
01103 //______________________________________________________________________________
01104 UInt_t TGTable::GetNDataRows() const
01105 {
01106    // Return the amount of rows in the data source.
01107 
01108    return fDataRange->fYbr - fDataRange->fYtl;
01109 }
01110 
01111 //______________________________________________________________________________
01112 UInt_t TGTable::GetNTableColumns() const
01113 {
01114    // Return the amount of columns in the table.
01115 
01116    return fCurrentRange->fXbr - fCurrentRange->fXtl;
01117 }
01118 
01119 //______________________________________________________________________________
01120 UInt_t TGTable::GetNDataColumns() const
01121 {
01122    // Return the amount of columns in the data source.
01123 
01124    return fDataRange->fYbr - fDataRange->fYtl;
01125 }
01126 
01127 //______________________________________________________________________________
01128 UInt_t TGTable::GetNTableCells() const
01129 {
01130    // Return the amount of cells in the table.
01131 
01132    return GetNTableRows() * GetNTableColumns();
01133 }
01134 
01135 //______________________________________________________________________________
01136 UInt_t TGTable::GetNDataCells() const
01137 {
01138    // Return the amount of cell in the data source.
01139 
01140    return GetNDataRows() * GetNDataColumns();
01141 }
01142 
01143 //______________________________________________________________________________
01144 const TTableRange *TGTable::GetCurrentRange() const
01145 {
01146    // Return the current range of the TGTable.
01147 
01148    return fCurrentRange;
01149 }
01150 
01151 //______________________________________________________________________________
01152 const TGTableHeader *TGTable::GetRowHeader(const UInt_t row) const
01153 {
01154    // Const version of GetRowHeader();
01155 
01156    return const_cast<TGTable *>(this)->GetRowHeader(row);
01157 }
01158 
01159 //______________________________________________________________________________
01160 TGTableHeader *TGTable::GetRowHeader(const UInt_t row)
01161 {
01162    // Return a pointer to the header of row.
01163 
01164    return (TGTableHeader *)fRowHeaders->At(row);
01165 }
01166 
01167 //______________________________________________________________________________
01168 const TGTableHeader *TGTable::GetColumnHeader(const UInt_t column) const
01169 {
01170    // Const version of GetColumnHeader();
01171 
01172    return const_cast<TGTable *>(this)->GetColumnHeader(column);
01173 }
01174 
01175 //______________________________________________________________________________
01176 TGTableHeader *TGTable::GetColumnHeader(const UInt_t column)
01177 {
01178    // Return a pointer to the header of column.
01179    
01180    return (TGTableHeader *)fColumnHeaders->At(column);
01181 }
01182 
01183 //______________________________________________________________________________
01184 TGTableHeader *TGTable::GetTableHeader()
01185 {
01186    // Return a pointer to the table header.
01187 
01188    return fTableHeader;
01189 }
01190 
01191 // //______________________________________________________________________________
01192 // const TGGC*  TGTable::GetSelectGC() const
01193 // {
01194 // }
01195 
01196 // //______________________________________________________________________________
01197 // const TGGC*  TGTable::GetCellBckgndGC(TGTableCell *cell) const
01198 // {
01199 // }
01200 
01201 // //______________________________________________________________________________
01202 // const TGGC*  TGTable::GetCellBckgndGC(UInt_t row, UInt_t column) const
01203 // {
01204 // }
01205 
01206 //______________________________________________________________________________
01207 Pixel_t TGTable::GetRowBackground(UInt_t row) const
01208 {
01209    // Get the background collor for row.
01210 
01211    if (row % 2 == 0) { // Even rows
01212       return fEvenRowBackground;
01213    } else {            // Odd rows
01214       return fOddRowBackground;
01215    }
01216 }
01217 
01218 //______________________________________________________________________________
01219 Pixel_t TGTable::GetHeaderBackground() const
01220 {
01221    // Get the background color of headers.
01222 
01223    return fHeaderBackground;
01224 }
01225 
01226 //______________________________________________________________________________
01227 void TGTable::SetOddRowBackground(Pixel_t pixel)
01228 {
01229    // Set the background color for all odd numbered rows.
01230 
01231    if(pixel == fOddRowBackground) return;
01232 
01233    fOddRowBackground = pixel;
01234 
01235    UInt_t nrows = GetNTableRows();
01236    UInt_t ncolumns = GetNTableColumns();
01237    UInt_t i = 0, j = 0;
01238    TGTableCell *cell = 0;
01239    
01240    for (i = 0; i < nrows; i++) {
01241       for (j = 0; j < ncolumns; j++) {
01242          if (i % 2) {
01243             cell = GetCell(i,j);
01244             cell->SetBackgroundColor(fOddRowBackground);
01245          }
01246       }
01247    }
01248    
01249    UInt_t width = fCanvas->GetViewPort()->GetWidth();
01250    UInt_t height = fCanvas->GetViewPort()->GetHeight();
01251    fTableFrame->DrawRegion(0, 0, width, height);
01252 }
01253 
01254 //______________________________________________________________________________
01255 void TGTable::SetEvenRowBackground(Pixel_t pixel)
01256 {
01257    // Set the background color for all even numbered rows.
01258 
01259    if(pixel == fEvenRowBackground) return;
01260 
01261    fEvenRowBackground = pixel;
01262 
01263    UInt_t nrows = GetNTableRows();
01264    UInt_t ncolumns = GetNTableColumns();
01265    UInt_t i = 0, j = 0;
01266    TGTableCell *cell = 0;
01267 
01268    for (i = 0; i < nrows; i++) {
01269       for (j = 0; j < ncolumns; j++) {
01270          if (!(i % 2)) { 
01271             cell = GetCell(i,j);
01272             cell->SetBackgroundColor(fEvenRowBackground);
01273          }
01274       }
01275    }
01276    UInt_t width = fCanvas->GetViewPort()->GetWidth();
01277    UInt_t height = fCanvas->GetViewPort()->GetHeight();
01278    fTableFrame->DrawRegion(0, 0, width, height);
01279 }
01280 
01281 //______________________________________________________________________________
01282 void TGTable::SetHeaderBackground(Pixel_t pixel)
01283 {
01284    // Set the background color for the headers.
01285 
01286    if(pixel == fHeaderBackground) return;
01287 
01288    fHeaderBackground = pixel;
01289 
01290    UInt_t nrows = GetNTableRows();
01291    UInt_t ncolumns = GetNTableColumns();
01292    UInt_t i = 0, j = 0;
01293    TGTableHeader *hdr = 0;
01294 
01295    for (i = 0; i < nrows; i++) {
01296       hdr = GetRowHeader(i);
01297       hdr->SetBackgroundColor(fHeaderBackground);
01298    }
01299    UInt_t height = fCanvas->GetViewPort()->GetHeight();
01300    UInt_t width = fTableHeader->GetWidth();
01301    fRHdrFrame->DrawRegion(0, 0, width, height);
01302 
01303    for (j = 0; j < ncolumns; j++) {
01304       hdr = GetColumnHeader(j);
01305       hdr->SetBackgroundColor(fHeaderBackground);
01306 //       gClient->NeedRedraw(hdr);
01307    }
01308    width = fCanvas->GetViewPort()->GetWidth();
01309    height = fTableHeader->GetHeight();
01310    fCHdrFrame->DrawRegion(0, 0, width, height);
01311 }
01312 
01313 //______________________________________________________________________________
01314 void TGTable::SetDefaultColors()
01315 {
01316    // Set the background color for all rows and headers to their defaults.
01317 
01318    SetEvenRowBackground(TColor::RGB2Pixel(204, 255, 204));
01319    SetOddRowBackground(TColor::RGB2Pixel(255, 255, 255));
01320    SetHeaderBackground(TColor::RGB2Pixel(204, 204, 255));
01321 }
01322 
01323 //______________________________________________________________________________
01324 void TGTable::MoveTable(Int_t rows, Int_t columns)
01325 {
01326    // Move and layout the table to the specified range. 
01327 
01328    if (fAllData) return;
01329 
01330    Int_t xtl = fCurrentRange->fXtl + columns;
01331    Int_t ytl = fCurrentRange->fYtl + rows;
01332    Int_t xbr = fCurrentRange->fXbr + columns;
01333    Int_t ybr = fCurrentRange->fYbr + rows;
01334 
01335    GotoTableRange(xtl, ytl, xbr, ybr);
01336 }
01337 
01338 //______________________________________________________________________________
01339 void TGTable::GotoTableRange(Int_t xtl,  Int_t ytl, Int_t xbr,  Int_t ybr)
01340 {
01341    // Move and resize the table to the specified range. 
01342 
01343    if (fAllData) return;
01344 
01345    if(xtl == xbr || ytl == ybr) {
01346       Error("TGTable::GotoTableRange","x or y range = 0");
01347       return;
01348    }
01349 
01350    Int_t nrows    = TMath::Abs(ybr - ytl);
01351    Int_t ncolumns = TMath::Abs(xbr - xtl);
01352 
01353    if (xtl > xbr) {
01354       Info("TGTable::GotoTableRange","Swapping x-range boundries");
01355       Int_t temp = xtl;
01356       xtl = xbr;
01357       xbr = temp;
01358    }
01359    if (ytl > ybr) {
01360       Info("TGTable::GotoTableRange","Swapping y-range boundries");
01361       Int_t temp = ytl;
01362       ytl = ybr;
01363       ybr = temp;
01364    }
01365    
01366    if((xtl < 0) || (xbr < 0)) {
01367       Info("TGTable::GotoTableRange", "Column boundry out of bounds, adjusting");
01368       xtl = 0;
01369       xbr = ncolumns;
01370       if (xbr > (Int_t)fDataRange->fXbr) {
01371          xbr = fDataRange->fXbr;
01372          ncolumns = TMath::Abs(xbr - xtl);
01373       }
01374    }
01375 
01376    if((ytl < 0) || (ybr < 0)) {
01377       Info("TGTable::GotoTableRange", "Row boundry out of bounds, adjusting");
01378       ytl = 0;
01379       ybr = nrows;
01380       if (ybr > (Int_t)fDataRange->fYbr) {
01381          ybr = fDataRange->fYbr;
01382          nrows =  TMath::Abs(ybr - ytl);
01383       }
01384    }
01385 
01386    if((xtl > (Int_t)fDataRange->fXbr) || (xbr > (Int_t)fDataRange->fXbr)) {
01387       Info("TGTable::GotoTableRange", "Left Column boundry out of bounds, "
01388            "adjusting");
01389       xbr = fDataRange->fXbr;
01390       xtl = xbr - ncolumns;
01391       if (xtl < 0) {
01392          xtl = 0;
01393          ncolumns = TMath::Abs(xbr - xtl);
01394          Info("TGTable::GotoTableRange", "Right column boundry out of"
01395                                          " bounds, set to 0");
01396       }
01397    }
01398    if ((ytl > (Int_t)fDataRange->fYbr) || (ybr > (Int_t)fDataRange->fYbr)) {
01399       Info("TGTable::GotoTableRange", "Bottom row boundry out of bounds, "
01400                                       "adjusting");
01401       ybr = fDataRange->fYbr;
01402       ytl = ybr - nrows;
01403       if (ytl < 0) {
01404          ytl = 0;
01405          nrows = ybr - ytl;
01406          Info("TGTable::GotoTableRange", "Top row boundry out of bounds, "
01407                                          "set to 0");
01408       }
01409    }
01410 
01411    nrows    = TMath::Abs(ybr - ytl);
01412    ncolumns = TMath::Abs(xbr - xtl);
01413 
01414    // Resize rows and columns if needed
01415    ResizeTable(nrows, ncolumns);
01416 
01417    fCurrentRange->fXtl = xtl;
01418    fCurrentRange->fYtl = ytl;
01419    fCurrentRange->fXbr = xbr;
01420    fCurrentRange->fYbr = ybr;
01421 
01422    // Update the table view.
01423    UpdateView();
01424 }
01425 
01426 //______________________________________________________________________________
01427 TGTableCell *TGTable::operator() (UInt_t row, UInt_t column)
01428 {
01429    // Operator for easy cell acces.
01430 
01431    return GetCell(row, column);
01432 }  
01433 
01434 //______________________________________________________________________________
01435 void TGTable::ScrollCHeaders(Int_t xpos)
01436 {
01437    // Scroll the column headers horizontally.
01438 
01439    if (!fCHdrFrame) return;   
01440 
01441    fCHdrFrame->Move(- xpos, 0);
01442    fCHdrFrame->Resize();
01443    fCHdrFrame->DrawRegion(0, 0, fCHdrFrame->GetWidth(), 
01444                           fCHdrFrame->GetHeight());
01445 }
01446 
01447 //______________________________________________________________________________
01448 void TGTable::ScrollRHeaders(Int_t ypos)
01449 {
01450    // Scroll the row headers vertically
01451 
01452    if (!fRHdrFrame) return;   
01453 
01454    fRHdrFrame->Move(fRHdrFrame->GetX(), -ypos);
01455    fRHdrFrame->Resize();
01456    fRHdrFrame->DrawRegion(0, 0, fRHdrFrame->GetWidth(), 
01457                           fRHdrFrame->GetHeight());
01458 }
01459 
01460 //______________________________________________________________________________
01461 void TGTable::NextChunk()
01462 {
01463    // Move the table to the next chunk of the data set with the same size.
01464 
01465    MoveTable(GetNTableRows(), 0);
01466    UpdateRangeFrame();
01467 }
01468 
01469 //______________________________________________________________________________
01470 void TGTable::PreviousChunk()
01471 {
01472    // Move the table to the previous chunk of the data set with the same size.
01473 
01474    MoveTable(-1 * (Int_t)GetNTableRows(), 0);
01475    UpdateRangeFrame();
01476 }
01477 
01478 //______________________________________________________________________________
01479 void TGTable::Goto()
01480 {
01481    // Slot used by the Goto button and whenever return is pressed in
01482    // on of the text entries in the range frame.
01483 
01484    if (fGotoButton->GetState() == kButtonUp) {
01485       GotoTableRange(fGotoRange->fXtl, fGotoRange->fYtl, 
01486                      fGotoRange->fXbr, fGotoRange->fYbr);
01487       UpdateRangeFrame();
01488    }
01489 }
01490 
01491 //______________________________________________________________________________
01492 void TGTable::UserRangeChange()
01493 {
01494    // Slot used when the text in one of the range frame text entries changes.
01495 
01496    TString topleft(fFirstCellEntry->GetText());
01497    if(!topleft.Contains(",")) return;
01498 
01499    Int_t pos = topleft.First(',');
01500    TString itl = topleft(0,pos);
01501    TString jtl = topleft(pos+1, topleft.Length());
01502 
01503    if (itl.Contains(' ') || itl.Contains('\t') || 
01504        jtl.Contains(' ') || jtl.Contains('\t')) return;
01505 
01506    if (!itl.IsAlnum() || !jtl.IsAlnum()) return;
01507 
01508    fGotoRange->fXtl = jtl.Atoi();
01509    fGotoRange->fYtl = itl.Atoi();
01510 
01511    TString range(fRangeEntry->GetText());
01512    if(!range.Contains("x")) return;
01513 
01514    pos = 0;
01515    pos = range.First('x');
01516    TString ir = range(0,pos);
01517    TString jr = range(pos+1, range.Length());
01518 
01519    if (ir.Contains(' ') || ir.Contains('\t') || 
01520        jr.Contains(' ') || jr.Contains('\t')) return;
01521    if (!ir.IsAlnum() || !jr.IsAlnum()) return;
01522 
01523    fGotoRange->fXbr = jtl.Atoi() + jr.Atoi();
01524    fGotoRange->fYbr = itl.Atoi() + ir.Atoi();
01525 
01526    if (*fGotoRange == *fCurrentRange) {
01527       fGotoButton->SetState(kButtonDisabled);
01528    } else {
01529       fGotoButton->SetState(kButtonUp);
01530    }
01531 
01532 }
01533 
01534 //______________________________________________________________________________
01535 void TGTable::Update() 
01536 {
01537    // Update the range of the available data and refresh the current view.
01538 
01539    fDataRange->fXbr = fInterface->GetNColumns();
01540    fDataRange->fYbr = fInterface->GetNRows();
01541    
01542    GotoTableRange(fCurrentRange->fXtl, fCurrentRange->fYtl,
01543                   fCurrentRange->fXbr, fCurrentRange->fYbr);
01544 
01545    UpdateView();
01546 }
01547 
01548 //______________________________________________________________________________
01549 TTableRange::TTableRange() : fXtl(0), fYtl(0), fXbr(0), fYbr(0)
01550 {
01551    // TTableRange constuctor.
01552 }
01553 
01554 //______________________________________________________________________________
01555 void TTableRange::Print()
01556 {
01557    // Print the values of a range.
01558 
01559    std::cout << "Range = (" << fXtl << "," << fYtl << ")->(" 
01560              << fXbr << "," << fYbr << ")" << std::endl;
01561 }
01562 
01563 //______________________________________________________________________________
01564 Bool_t TTableRange::operator==(TTableRange &other)
01565 {
01566    // Operator to determine if 2 ranges are equal
01567 
01568    if ((fXtl == other.fXtl) && (fYtl == other.fYtl) && 
01569        (fXbr == other.fXbr) && (fYbr == other.fYbr)) {
01570       return kTRUE;
01571    } else {
01572       return kFALSE;
01573    }           
01574 }

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