#include "TROOT.h" #include "TApplication.h" #include "TVirtualX.h" #include "TGClient.h" #include "TGFrame.h" #include "TGMenu.h" #include "TGListView.h" #include "TGPicture.h" #include "TGResourcePool.h" #include "TRandom.h" class TestListView : public TGMainFrame { protected: TGListView *fList; TGLVContainer *fContents; TGPopupMenu *fMenu; const TGPicture *fSPic, *fLPic; public: TestListView(const TGWindow *p, UInt_t w, UInt_t h); virtual ~TestListView(); // slots void OnClicked(TGLVEntry *f, Int_t btn); void OnClicked(TGLVEntry *f, Int_t btn, Int_t x, Int_t y); void OnDblClicked(TGLVEntry *f, Int_t btn); void OnDblClicked(TGLVEntry *f, Int_t btn, Int_t x, Int_t y); void CloseWindow(); void DoMenu(Int_t); void FillLV(); }; //______________________________________________________________________________ TestListView::TestListView(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h) { // Create transient frame containing a filelist widget. TGLayoutHints *lo; // use hierarchical cleaning SetCleanup(kDeepCleanup); TGMenuBar* mb = new TGMenuBar(this); lo = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1); AddFrame(mb, lo); fMenu = mb->AddPopup("&View"); fMenu->AddEntry("Lar&ge Icons",kLVLargeIcons); fMenu->AddEntry("S&mall Icons",kLVSmallIcons); fMenu->AddEntry("&List", kLVList); fMenu->AddEntry("&Details", kLVDetails); fMenu->AddSeparator(); fMenu->AddEntry("&Fill", 10); fMenu->AddSeparator(); fMenu->AddEntry("&Close", 20); fMenu->Connect("Activated(Int_t)","TestListView",this,"DoMenu(Int_t)"); fList = new TGListView(this, w, h); lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY); AddFrame(fList, lo); fList->SetHeaders(2); fList->SetHeader("ServerName", kTextLeft, kTextLeft, 0); fList->SetHeader("Status", kTextLeft, kTextLeft, 1); fSPic = gClient->GetPicture("ntuple_t.xpm"); fLPic = gClient->GetPicture("ntuple_s.xpm"); fList->Connect("Clicked(TGLVEntry *, Int_t)", "TestListView", this, "OnClicked(TGLVEntry*,Int_t)"); fList->Connect("Clicked(TGLVEntry *, Int_t, Int_t, Int_t)", "TestListView", this, "OnClicked(TGLVEntry*,Int_t, Int_t, Int_t)"); fList->Connect("DoubleClicked(TGLVEntry *, Int_t)", "TestListView", this, "OnDblClicked(TGLVEntry*,Int_t)"); fList->Connect("DoubleClicked(TGLVEntry *, Int_t, Int_t, Int_t)", "TestListView", this, "OnDblClicked(TGLVEntry*,Int_t, Int_t, Int_t)"); Pixel_t white; gClient->GetColorByName("white", white); fContents = new TGLVContainer(fList->GetViewPort(), 9, 9, kSunkenFrame, white); fList->SetContainer(fContents); fContents->Associate(fList); fList->SetViewMode(kLVDetails); SetWindowName("ListView Test"); MapSubwindows(); MapWindow(); Resize(); FillLV(kTRUE); } //______________________________________________________________________________ TestListView::~TestListView() { // Cleanup. } //______________________________________________________________________________ void TestListView::CloseWindow() { gClient->FreePicture(fLPic); gClient->FreePicture(fSPic); delete fContents; delete fMenu; DeleteWindow(); } //______________________________________________________________________________ void TestListView::DoMenu(Int_t mode) { // Switch view mode. if (mode < 10) { fContents->SetViewMode((EListViewMode)mode); } else if (mode < 20) { FillLV(kFALSE); } else { CloseWindow(); } } //______________________________________________________________________________ void TestListView::FillLV(Bool_t reset) { if (reset) fContents->RemoveAll(); TGString *sname = new TGString("Name of a server"); TGString **sub = new TGString* [2]; Int_t status = (Int_t)gRandom->Uniform(0,3); switch (status) { case 0: sub[0] = new TGString("Not running"); break; case 1: sub[0] = new TGString("Running"); break; default: sub[0] = new TGString("Unknown"); break; } sub[1] = 0; fContents->AddItem(new TGLVEntry(fContents, fLPic, fSPic, sname, sub, kLVDetails)); fList->ResizeColumns(); } //______________________________________________________________________________ void TestListView::OnClicked(TGLVEntry *f, Int_t btn) { printf("Clicked(0x%lx, btn=%d)\n", f, btn); } //______________________________________________________________________________ void TestListView::OnClicked(TGLVEntry *f, Int_t btn, Int_t x, Int_t y) { printf("Clicked(0x%lx, btn=%d, x=%d, y=%d)\n", f, btn, x, y); } //______________________________________________________________________________ void TestListView::OnDblClicked(TGLVEntry *f, Int_t btn) { printf("DoubleClicked(0x%lx, btn=%d)\n", f, btn); } //______________________________________________________________________________ void TestListView::OnDblClicked(TGLVEntry *f, Int_t btn, Int_t x, Int_t y) { printf("DoubleClicked(0x%lx, btn=%d, x=%d, y=%d)\n", f, btn, x, y); } //______________________________________________________________________________ void TestListView() { new TestListView(gClient->GetRoot(), 240, 300); }