#include "TGFrame.h" #include "TGButton.h" #include "TGCanvas.h" #include "TGTextEntry.h" class Table : public TGMainFrame { private: public: Table(const TGWindow *p, UInt_t w, UInt_t h, Int_t columns, Int_t rows); virtual ~Table() { } void Create(Int_t columns, Int_t rows); ClassDef(Table, 0) }; Table::Table(const TGWindow *p, UInt_t w, UInt_t h, Int_t columns, Int_t rows) : TGMainFrame(p, w, h) { // Create main frame Create(columns, rows); SetCleanup(kDeepCleanup); } void Table::Create(Int_t columns, Int_t rows) { TGLayoutHints *layout1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 20, 20, 10, 0); TGLayoutHints *layout2 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1); TGCanvas *Viewer = new TGCanvas(this, 100, 100, kFixedWidth | kFixedHeight); TGCompositeFrame *Container = new TGCompositeFrame(Viewer->GetViewPort(), 50, 50); Container->SetCleanup(kDeepCleanup); Viewer->GetViewPort()->SetCleanup(kDeepCleanup); Viewer->SetContainer(Container); AddFrame(Viewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); TGHorizontalFrame *hf = new TGHorizontalFrame(Container, 200, 300); TGTextButton **But = new TGTextButton *[rows + columns]; TGTextEntry **Entry = new TGTextEntry *[rows * columns]; TGVerticalFrame **Column = new TGVerticalFrame *[columns]; for (int i = 0; i < columns; i++) { Column[i] = new TGVerticalFrame(hf, 200, 300); hf->AddFrame(Column[i], new TGLayoutHints (kLHintsTop | kLHintsLeft, 0, 0, 0, 0)); if (i == 0) { for (int j = 0; j < rows; j++) { if (j == 0) But[j] = new TGTextButton(Column[i], " "); else But[j] = new TGTextButton(Column[i], TString::Format(" Line %d ", j)); Column[i]->AddFrame(But[j], layout2); } } else { for (int j = 0; j < rows; j++) { if (j == 0) { But[(i*rows)+j] = new TGTextButton(Column[i], TString::Format("Column %d", i)); Column[i]->AddFrame(But[(i*rows)+j], layout2); } else { Entry[(i*rows)+j] = new TGTextEntry(Column[i]); Column[i]->AddFrame(Entry[(i*rows)+j], layout2); } } } } Container->AddFrame(hf, layout1); MapSubwindows(); MapWindow(); Layout(); } void test_table(Int_t columns = 5, Int_t rows = 20) { new Table(gClient->GetRoot(), 400, 200, columns, rows); }