// Test gui //#ifndef __CINT__ #include "RQ_OBJECT.h" #include "TG3DLine.h" #include "TGButton.h" #include "TGComboBox.h" #include "TGFrame.h" #include "TGLabel.h" #include "TGLayout.h" #include "TGListBox.h" #include "TGMenu.h" #include "TGTab.h" #include "TList.h" #include "TString.h" #include "TROOT.h" #include "TSystem.h" //#endif #include // Menu commands enum EMenuCommands { M_FILE, M_FILE_EXIT, }; class XFrameGroups { RQ_OBJECT("XFrameGroups") private: TGCompositeFrame *fFrame; TGCanvas *fCanvas; TGTab *fTab; TGCompositeFrame *fFTab1; //Tab 1 TGGroupFrame *fFG1; TGCompositeFrame *fFTest; //Tab Test TGGroupFrame *fFGTst; TGComboBox *fTestBox; TGGroupFrame *fFGroup1; TGGroupFrame *fFGroup2; TGLayoutHints *fHintTL; TGLayoutHints *fHintXY; TGLayoutHints *fHintRXY; TList *fTrash; Int_t fTestID; public: XFrameGroups() {} XFrameGroups(TGCompositeFrame *parent, UInt_t w, UInt_t h); virtual ~XFrameGroups(); void DoSelectGroup(Int_t id = -1); private: void CreateTab1(TGTab *tab); void DeleteTab1(); void CreateTabTest(TGTab *tab); void DeleteTabTest(); void CreateGroup1(TGCompositeFrame *parent); void DeleteGroup1(); void CreateGroup2(TGCompositeFrame *parent); void DeleteGroup2(); #if !defined (__CINT__) || defined (__MAKECINT__) ClassDef(XFrameGroups,0) //XFrameGroups #endif }; class XTestFrame { RQ_OBJECT("XTestFrame") private: TGCompositeFrame *fFrame; XFrameGroups *fFrameGroups; TGLayoutHints *fHintTXY; public: XTestFrame() {} XTestFrame(TGCompositeFrame *parent, UInt_t w, UInt_t h); virtual ~XTestFrame(); private: void CreateGroupFrames(TGCompositeFrame *parent); void DeleteGroupFrames(); #if !defined (__CINT__) || defined (__MAKECINT__) ClassDef(XTestFrame,0) //XTestFrame #endif }; class XFrameTestGroups { RQ_OBJECT("XFrameTestGroups") private: TGMainFrame *fMain; TGPopupMenu *fMenuFile; TGMenuBar *fMenuBar; TGHorizontal3DLine *fLineH1; TGLayoutHints *fMenuBarLayout; TGLayoutHints *fMenuBarItemLayout; TGLayoutHints *fLineLayout; TGCompositeFrame *fFrame; XTestFrame *fTestFrame; public: XFrameTestGroups() {} XFrameTestGroups(const TGWindow *window, UInt_t w, UInt_t h); virtual ~XFrameTestGroups(); void DoMenu(Int_t id); void DoCloseWindow(); private: void CreateMenuBar(); void DeleteMenuBar(); void CreateTestFrame(TGCompositeFrame *parent); void DeleteTestFrame(); #if !defined (__CINT__) || defined (__MAKECINT__) ClassDef(XFrameTestGroups,0) //XFrameTestGroups #endif }; // Test Ids enum ETest { CB_GROUP1 = 1, CB_GROUP2, }; const Int_t kNTest = 2; const char *kTest[2] = { "Group 1", "Group 2"}; //debug: print function names const Bool_t kCS = 1; #if !defined (__CINT__) || defined (__MAKECINT__) ClassImp(XFrameGroups); ClassImp(XTestFrame); ClassImp(XFrameTestGroups); #endif //______________________________________________________________________________ XFrameTestGroups::XFrameTestGroups(const TGWindow *window, UInt_t w, UInt_t h) { if(kCS) cout << "------XFrameTestGroups::XFrameTestGroups------" << endl; fMain = new TGMainFrame(window, w, h); fMain->Connect("CloseWindow()", "XFrameTestGroups", this, "DoCloseWindow()"); CreateMenuBar(); fFrame = new TGVerticalFrame(fMain, w, h); fFrame->Resize(200, 260); fMain->AddFrame(fFrame); // fMain->AddFrame(fFrame, fHintRXY); CreateTestFrame(fFrame); fMain->SetWindowName("TestGroups"); fMain->MapSubwindows(); fMain->Resize(600, 420); fMain->MapWindow(); fMain->Move(420, 20); }//Constructor //______________________________________________________________________________ XFrameTestGroups::~XFrameTestGroups() { if(kCS) cout << "------XFrameTestGroups::~XFrameTestGroups------" << endl; DeleteMenuBar(); DeleteTestFrame(); delete fFrame; delete fMain; }//Destructor //______________________________________________________________________________ void XFrameTestGroups::CreateMenuBar() { if(kCS) cout << "------XFrameTestGroups::CreateMenuBar------" << endl; fMenuFile = new TGPopupMenu(gClient->GetRoot()); fMenuFile->AddEntry("&Exit", M_FILE_EXIT); fMenuFile->Connect("Activated(Int_t)","XFrameTestGroups",this,"DoMenu(Int_t)"); fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1); fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame); fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout); fMain->AddFrame(fMenuBar, fMenuBarLayout); fLineH1 = new TGHorizontal3DLine(fMain); fLineLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX); fMain->AddFrame(fLineH1, fLineLayout); fLineH1->DrawBorder(); }//CreateMenuBar //______________________________________________________________________________ void XFrameTestGroups::DeleteMenuBar() { if(kCS) cout << "------XFrameTestGroups::DeleteMenuBar------" << endl; delete fLineLayout; delete fLineH1; delete fMenuBarLayout; delete fMenuBarItemLayout; delete fMenuBar; delete fMenuFile; }//DeleteMenuBar //______________________________________________________________________________ void XFrameTestGroups::DoMenu(Int_t id) { if(kCS) cout << "------XFrameTestGroups::DoMenu------" << endl; switch (id) { case M_FILE_EXIT: DoCloseWindow(); break; default: printf("Error: Unknown ID %d selected\n", id); break; } }//DoMenu //______________________________________________________________________________ void XFrameTestGroups::DoCloseWindow() { if(kCS) cout << "------XFrameTestGroups::DoCloseWindow------" << endl; delete this; //does not exit root // gApplication->Terminate(0); //exit root, needed for standalone App }//DoCloseWindow //______________________________________________________________________________ void XFrameTestGroups::CreateTestFrame(TGCompositeFrame *parent) { if(kCS) cout << "------XFrameTestGroups::CreateTestFrame------" << endl; fTestFrame = new XTestFrame(parent, 0, 0); }//CreateTestFrame //______________________________________________________________________________ void XFrameTestGroups::DeleteTestFrame() { if(kCS) cout << "------XFrameTestGroups::DeleteTestFrame------" << endl; delete fTestFrame; }//DeleteTestFrame //______________________________________________________________________________ //______________________________________________________________________________ XTestFrame::XTestFrame(TGCompositeFrame *parent, UInt_t w, UInt_t h) { if(kCS) cout << "------XTestFrame::XTestFrame------" << endl; fFrame = new TGCompositeFrame(parent, w, h); fHintTXY = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY); parent->AddFrame(fFrame, fHintTXY); CreateGroupFrames(fFrame); }//Constructor //______________________________________________________________________________ XTestFrame::~XTestFrame() { if(kCS) cout << "------XTestFrame::~XTestFrame------" << endl; DeleteGroupFrames(); delete fHintTXY; delete fFrame; }//Destructor //______________________________________________________________________________ void XTestFrame::CreateGroupFrames(TGCompositeFrame *parent) { if(kCS) cout << "------XTestFrame::CreateGroupFrames------" << endl; fFrameGroups = new XFrameGroups(parent, 0, 0); }//CreateGroupFrames //______________________________________________________________________________ void XTestFrame::DeleteGroupFrames() { if(kCS) cout << "------XTestFrame::DeleteGroupFrames------" << endl; delete fFrameGroups; }//DeleteGroupFrames //______________________________________________________________________________ //______________________________________________________________________________ XFrameGroups::XFrameGroups(TGCompositeFrame *parent, UInt_t w, UInt_t h) { if(kCS) cout << "------XFrameGroups::XFrameGroups------" << endl; fTestID = 1; fTrash = new TList(); fHintTL = new TGLayoutHints(kLHintsTop | kLHintsLeft); fHintXY = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY); fHintRXY = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY); fFrame = new TGVerticalFrame(parent, w, h); fCanvas = new TGCanvas(fFrame, w, h, 0); fTab = new TGTab(fCanvas->GetViewPort(), 200, 20); fTab->Associate(parent); //? fCanvas->SetContainer(fTab); // CreateTab1(fTab); // CreateTabTest(fTab); fFrame->AddFrame(fCanvas, fHintXY); fFrame->Resize(600, 360); parent->AddFrame(fFrame, fHintRXY); CreateTab1(fTab); CreateTabTest(fTab); // fFGTst->HideFrame(fFGroup2); }//Constructor //______________________________________________________________________________ XFrameGroups::~XFrameGroups() { if(kCS) cout << "------XFrameGroups::~XFrameGroups------" << endl; delete fHintTL; delete fHintXY; delete fHintRXY; DeleteTabTest(); DeleteTab1(); delete fTab; delete fCanvas; delete fFrame; fTrash->Delete(); delete fTrash; }//Destructor //______________________________________________________________________________ void XFrameGroups::DoSelectGroup(Int_t id) { if(kCS) cout << "------XFrameGroups::DoSelectGroup------" << endl; if (id == fTestID) return; fFGTst->HideFrame(fFGroup1); fFGTst->HideFrame(fFGroup2); switch (id) { case CB_GROUP1: fFGTst->ShowFrame(fFGroup1); break; case CB_GROUP2: fFGTst->ShowFrame(fFGroup2); break; default: printf("Error: Unknown ID %d selected\n", id); break; }//switch //NOTE: uncommenting these lines result that Group2 can no longer be selected!!! // fFGTst->MapSubwindows(); // fFGTst->Layout(); fTestID = id; }//DoSelectGroup //______________________________________________________________________________ void XFrameGroups::CreateTab1(TGTab *tab) { if(kCS) cout << "------XFrameGroups::CreateTab1------" << endl; TGLayoutHints *hint = 0; TGCompositeFrame *tabframe = 0; tabframe = tab->AddTab("Tab 1"); fFTab1 = new TGCompositeFrame(tabframe, 20, 20, kVerticalFrame); hint = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 5); tabframe->AddFrame(fFTab1, hint); fTrash->Add(hint); fFG1 = new TGGroupFrame(fFTab1, "Group Tab 1", kVerticalFrame); hint = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 10, 10); fFTab1->AddFrame(fFG1, hint); fTrash->Add(hint); fFG1->Resize(400,200); TGLabel *lab = new TGLabel(fFG1, new TGString("Group for Tab 1")); hint = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 5); fFG1->AddFrame(lab,hint); fTrash->Add(hint); fTrash->Add(lab); }//CreateTab1 //______________________________________________________________________________ void XFrameGroups::DeleteTab1() { if(kCS) cout << "------XFrameGroups::DeleteTab1------" << endl; delete fFG1; delete fFTab1; }//DeleteTab1 //______________________________________________________________________________ void XFrameGroups::CreateTabTest(TGTab *tab) { if(kCS) cout << "------XFrameGroups::CreateTabTest------" << endl; TGLayoutHints *hint = 0; TGCompositeFrame *tabframe = 0; tabframe = tab->AddTab("Group Test"); fFTest = new TGCompositeFrame(tabframe, 20, 20, kVerticalFrame); hint = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 5); tabframe->AddFrame(fFTest, hint); fTrash->Add(hint); fFGTst = new TGGroupFrame(fFTest, "Select Group", kVerticalFrame | kFixedSize); fFTest->AddFrame(fFGTst, fHintTL); fFGTst->Resize(600,460); fTestBox = new TGComboBox(fFGTst, -1); fTestBox->Connect("Selected(Int_t)", "XFrameGroups", this, "DoSelectGroup(Int_t)"); hint = new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 15, 15); fFGTst->AddFrame(fTestBox, hint); fTestBox->Resize(250, 20); for (Int_t i = 0; i < kNTest; i++) { fTestBox->AddEntry(kTest[i], i+1); }//for_i // fTestBox->Select(1); CreateGroup1(fFGTst); CreateGroup2(fFGTst); // workaround suggested by Ilka Antcheva: fFGTst->Resize(fFGTst->GetDefaultSize()); fFGTst->MapSubwindows(); // fFGTst->HideFrame(fFGroup1); fFGTst->HideFrame(fFGroup2); fFGTst->MapWindow(); // fFGTst->Layout(); fTestBox->Select(2); // DoSelectGroup(2); /* fFGTst->HideFrame(fFGroup2); fFGTst->MapSubwindows(); fFGTst->Layout(); */ }//CreateTabTest //______________________________________________________________________________ void XFrameGroups::DeleteTabTest() { if(kCS) cout << "------XFrameGroups::DeleteTabTest------" << endl; DeleteGroup2(); DeleteGroup1(); delete fTestBox; delete fFGTst; delete fFTest; }//DeleteTabTest //______________________________________________________________________________ void XFrameGroups::CreateGroup1(TGCompositeFrame *parent) { if(kCS) cout << "------XFrameGroups::CreateGroup1------" << endl; TGLayoutHints *hint = 0; fFGroup1 = new TGGroupFrame(parent, "Group 1", kVerticalFrame); hint = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 10, 10); parent->AddFrame(fFGroup1, hint); fTrash->Add(hint); fFGroup1->Resize(400,200); TGLabel *lab = new TGLabel(fFGroup1, new TGString("This is Group 1")); hint = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 5); fFGroup1->AddFrame(lab,hint); fTrash->Add(hint); fTrash->Add(lab); }//CreateGroup1 //______________________________________________________________________________ void XFrameGroups::DeleteGroup1() { if(kCS) cout << "------XFrameGroups::DeleteGroup1------" << endl; delete fFGroup1; }//DeleteGroup1 //______________________________________________________________________________ void XFrameGroups::CreateGroup2(TGCompositeFrame *parent) { if(kCS) cout << "------XFrameGroups::CreateGroup2------" << endl; TGLayoutHints *hint = 0; fFGroup2 = new TGGroupFrame(parent, "Group 2", kVerticalFrame); hint = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 10, 10); parent->AddFrame(fFGroup2, hint); fTrash->Add(hint); fFGroup2->Resize(400,200); TGLabel *lab = new TGLabel(fFGroup2, new TGString("This is Group 2!!")); hint = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 5); fFGroup2->AddFrame(lab,hint); fTrash->Add(hint); fTrash->Add(lab); parent->HideFrame(fFGroup2); }//CreateGroup2 //______________________________________________________________________________ void XFrameGroups::DeleteGroup2() { if(kCS) cout << "------XFrameGroups::DeleteGroup2------" << endl; delete fFGroup2; }//DeleteGroup2 //______________________________________________________________________________ void guiTestGroups1() { new XFrameTestGroups(gClient->GetRoot(), 400, 220); }