ROOT logo

From $ROOTSYS/tutorials/gui/simpleTableTest.C

// This TableTest class is a simple example of how to use a TGSimpleTable 
// that creates and owns it's own TGSimpleTableInterface. 
// TableTest inherits from TGMainFrame to
// create a top level frame to embed the TGTable in. First the data
// needed is created. Then the TGSimpleTable is created using this
// data. In the end, the table is added to the TGMainFrame that is the
// TableTest and the necessary calls to correctly draw the window are
// made. For more information about the use of TGSimpleTable see it's
// documentation.

// author: Roel Aaij 13/07/2007

#include <iostream>
#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TString.h>
#include <TGButtonGroup.h>
#include <TGMenu.h>
#include <TGSimpleTable.h>

// A little class to automatically handle the generation of unique
// widget ids.
class IDList {
private:
   Int_t nID ;               // Generates unique widget IDs.
public:
   IDList() : nID(0) {}
   ~IDList() {}
   Int_t GetUnID(void) { return ++nID ; }
} ;

class TableTest : public TGMainFrame {

private:
   IDList         IDs ;      // Generator for unique widget IDs.
   Double_t     **fData;
   UInt_t         fNDataRows;
   UInt_t         fNDataColumns;
   UInt_t         fNTableRows;
   UInt_t         fNTableColumns;
   TGSimpleTable *fSimpleTable;
   
public:
   TableTest(const TGWindow *p, UInt_t ndrows, UInt_t ndcols, 
             UInt_t ntrows, UInt_t ntcols, UInt_t w = 100, UInt_t h = 100) ;
   virtual ~TableTest() ;

   void DoExit() ;

   TGSimpleTable *GetTable() { return fSimpleTable; }

   ClassDef(TableTest, 0)
};
                          
TableTest::TableTest(const TGWindow *p,  UInt_t ndrows, UInt_t ndcols, 
                     UInt_t ntrows, UInt_t ntcols, UInt_t w, UInt_t h) 
   : TGMainFrame(p, w, h), fData(0), fNDataRows(ndrows), fNDataColumns(ndcols),
     fNTableRows(ntrows), fNTableColumns(ntcols), fSimpleTable(0)
{
   SetCleanup(kDeepCleanup) ;   
   Connect("CloseWindow()", "TableTest", this, "DoExit()") ;
   DontCallClose() ;
      
   // Create the needed data.
   Int_t i = 0, j = 0; 
   fData = new Double_t*[fNDataRows];
   for (i = 0; i < (Int_t)fNDataRows; i++) {
      fData[i] = new Double_t[fNDataColumns];
      for (j = 0; j < (Int_t)fNDataColumns; j++) {
         fData[i][j] = 10 * i + j;
      }
   }
   
   // Create the table and add it to the TableTest that is a TGMainFrame.
   fSimpleTable = new TGSimpleTable(this, IDs.GetUnID(), fData, fNTableRows, 
                                    fNTableColumns);
   AddFrame(fSimpleTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
   
   // Calls to layout and draw the TableTest that is a TGMainFrame.
   SetWindowName("TGSimpleTable Test") ;
   MapSubwindows() ;
   Layout();
   Resize(GetDefaultWidth()+20, 600) ;
   MapWindow() ;
   
} ;

TableTest::~TableTest()
{
   // Destructor
   UInt_t i = 0; 
   for (i = 0; i < fNDataRows; i++) {
      delete[] fData[i];
   }
   delete[] fData;
   Cleanup() ;
 }
 
 void TableTest::DoExit()
{
   // Exit this application via the Exit button or Window Manager.
   // Use one of the both lines according to your needs.
   // Please note to re-run this macro in the same ROOT session,
   // you have to compile it to get signals/slots 'on place'.
   
   DeleteWindow();            // to stay in the ROOT session
   //   gApplication->Terminate();   // to exit and close the ROOT session   
}

TGSimpleTable *simpleTableTest(UInt_t ndrows = 500, UInt_t ndcols = 20, 
                   UInt_t ntrows = 50, UInt_t ntcols = 10) {
   TableTest *test = new TableTest(0, ndrows, ndcols, ntrows, ntcols, 500, 200);
   return test->GetTable();
}
 simpleTableTest.C:1
 simpleTableTest.C:2
 simpleTableTest.C:3
 simpleTableTest.C:4
 simpleTableTest.C:5
 simpleTableTest.C:6
 simpleTableTest.C:7
 simpleTableTest.C:8
 simpleTableTest.C:9
 simpleTableTest.C:10
 simpleTableTest.C:11
 simpleTableTest.C:12
 simpleTableTest.C:13
 simpleTableTest.C:14
 simpleTableTest.C:15
 simpleTableTest.C:16
 simpleTableTest.C:17
 simpleTableTest.C:18
 simpleTableTest.C:19
 simpleTableTest.C:20
 simpleTableTest.C:21
 simpleTableTest.C:22
 simpleTableTest.C:23
 simpleTableTest.C:24
 simpleTableTest.C:25
 simpleTableTest.C:26
 simpleTableTest.C:27
 simpleTableTest.C:28
 simpleTableTest.C:29
 simpleTableTest.C:30
 simpleTableTest.C:31
 simpleTableTest.C:32
 simpleTableTest.C:33
 simpleTableTest.C:34
 simpleTableTest.C:35
 simpleTableTest.C:36
 simpleTableTest.C:37
 simpleTableTest.C:38
 simpleTableTest.C:39
 simpleTableTest.C:40
 simpleTableTest.C:41
 simpleTableTest.C:42
 simpleTableTest.C:43
 simpleTableTest.C:44
 simpleTableTest.C:45
 simpleTableTest.C:46
 simpleTableTest.C:47
 simpleTableTest.C:48
 simpleTableTest.C:49
 simpleTableTest.C:50
 simpleTableTest.C:51
 simpleTableTest.C:52
 simpleTableTest.C:53
 simpleTableTest.C:54
 simpleTableTest.C:55
 simpleTableTest.C:56
 simpleTableTest.C:57
 simpleTableTest.C:58
 simpleTableTest.C:59
 simpleTableTest.C:60
 simpleTableTest.C:61
 simpleTableTest.C:62
 simpleTableTest.C:63
 simpleTableTest.C:64
 simpleTableTest.C:65
 simpleTableTest.C:66
 simpleTableTest.C:67
 simpleTableTest.C:68
 simpleTableTest.C:69
 simpleTableTest.C:70
 simpleTableTest.C:71
 simpleTableTest.C:72
 simpleTableTest.C:73
 simpleTableTest.C:74
 simpleTableTest.C:75
 simpleTableTest.C:76
 simpleTableTest.C:77
 simpleTableTest.C:78
 simpleTableTest.C:79
 simpleTableTest.C:80
 simpleTableTest.C:81
 simpleTableTest.C:82
 simpleTableTest.C:83
 simpleTableTest.C:84
 simpleTableTest.C:85
 simpleTableTest.C:86
 simpleTableTest.C:87
 simpleTableTest.C:88
 simpleTableTest.C:89
 simpleTableTest.C:90
 simpleTableTest.C:91
 simpleTableTest.C:92
 simpleTableTest.C:93
 simpleTableTest.C:94
 simpleTableTest.C:95
 simpleTableTest.C:96
 simpleTableTest.C:97
 simpleTableTest.C:98
 simpleTableTest.C:99
 simpleTableTest.C:100
 simpleTableTest.C:101
 simpleTableTest.C:102
 simpleTableTest.C:103
 simpleTableTest.C:104
 simpleTableTest.C:105
 simpleTableTest.C:106
 simpleTableTest.C:107
 simpleTableTest.C:108
 simpleTableTest.C:109
 simpleTableTest.C:110
 simpleTableTest.C:111
 simpleTableTest.C:112
 simpleTableTest.C:113
 simpleTableTest.C:114
 simpleTableTest.C:115
 simpleTableTest.C:116
 simpleTableTest.C:117
 simpleTableTest.C:118
 simpleTableTest.C:119
 simpleTableTest.C:120
 simpleTableTest.C:121