#include #include #include #include #include #include class MultiEmbeddedCanvas { RQ_OBJECT("MultiEmbeddedCanvas") private: TGMainFrame *fMain; TList lCanvases; UInt_t fNumberOfCanvases; TGVerticalFrame *fVer; TGComboBox *fCombo; public: MultiEmbeddedCanvas(const TGWindow *p, UInt_t w, UInt_t h); virtual ~MultiEmbeddedCanvas(); // slots void DoSelection(); void AddCanvas(); void Exit(); }; void MultiEmbeddedCanvas::Exit() { fMain->UnmapWindow(); //delete fMain; } void MultiEmbeddedCanvas::DoSelection(Int_t id) { // Select a canvas from the list. Printf("Select a canvas from the list..."); TIter canIter(&(lCanvases)); while((em = (TRootEmbeddedCanvas*) canIter.Next())) { fVer->HideFrame(em); } TRootEmbeddedCanvas* ec = (TRootEmbeddedCanvas*)lCanvases.At(id); fVer->ShowFrame(ec); ec->GetCanvas()->cd(); } void MultiEmbeddedCanvas::AddCanvas() { TRootEmbeddedCanvas *fEcan; TRootEmbeddedCanvas *em; char tmp[20]; sprintf(tmp, "Canvas %i", fNumberOfCanvases); Printf("Add a canvas"); //Hide all the canvases TIter canIter(&(lCanvases)); while((em = (TRootEmbeddedCanvas*) canIter.Next())) { //Printf("Hide canvas %s", em->GetCanvas()->GetName()); fVer->HideFrame(em); } // Create an embedded canvas and add it to the main frame fEcan = new TRootEmbeddedCanvas (tmp, fVer, 700, 700); fVer->AddFrame (fEcan, new TGLayoutHints (kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10)); fEcan->GetCanvas()->Range(0,0,1,1); fEcan->GetCanvas()->SetBorderSize(2); fEcan->GetCanvas()->SetFrameFillColor(10); fEcan->GetCanvas()->cd(); lCanvases.Add(fEcan); ellipse1 = new TEllipse(0.25,0.6,0.2,0.1,0,360,0); ellipse1->SetFillColor((Int_t)gRandom->Uniform(1,30)); ellipse1->SetFillStyle(3008); ellipse1->Draw(); title = new TPaveLabel(0, 0, 0.5, 0.5, tmp); title->Draw(); //add the canvas in the combo box fCombo->AddEntry(tmp, fNumberOfCanvases); fNumberOfCanvases++; fMain->MapSubwindows(); // Map main frame fMain->MapWindow(); fMain->Resize(); } MultiEmbeddedCanvas::MultiEmbeddedCanvas(const TGWindow *p, UInt_t w, UInt_t h) { // Create a main frame fMain = new TGMainFrame(p, w, h); fMain->SetWMPosition(0,0); // Create a vertical frame containing the canvases fVer = new TGVerticalFrame(fMain, 10, 5, kSunkenFrame); fMain->AddFrame(fVer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5)); // Create a horizontal frame containing a combo box and two text buttons TGHorizontalFrame *fHor = new TGHorizontalFrame(fMain, 10, 5); fNumberOfCanvases = 0; //cambo box with the list of canvases created fCombo = new TGComboBox(fHor, 98); fCombo->Connect("Selected(Int_t)", "MultiEmbeddedCanvas", this, "DoSelection(Int_t)"); fCombo->Resize(120, 20); fHor->AddFrame(fCombo, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5)); fAdd = new TGTextButton(fHor, " &Add "); fAdd->SetToolTipText("Add a TRootEmbeddedCanvas"); fHor->AddFrame(fAdd, new TGLayoutHints(kLHintsTop | kLHintsLeft, 200, 5, 5, 5)); fAdd->Connect("Clicked()", "MultiEmbeddedCanvas", this, "AddCanvas()"); fExit = new TGTextButton(fHor, " &Exit "); //fExit->SetCommand("gApplication->Terminate()"); fExit->SetToolTipText("Click on the button to terminate the application"); fHor->AddFrame(fExit, new TGLayoutHints(kLHintsTop | kLHintsRight, 200, 5, 5, 5)); fExit->Connect("Clicked()", "MultiEmbeddedCanvas", this, "Exit()"); fMain->AddFrame(fHor, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); // Set a name to the main frame fMain->SetWindowName("Test of TRootEmbeddedCanvas creation"); fMain->MapSubwindows(); //initialize the layout algorithm via Resize() fMain->MapSubwindows(); // Map main frame fMain->MapWindow(); fMain->Resize(); fMain->Resize(w,h); } MultiEmbeddedCanvas::~MultiEmbeddedCanvas() { // Clean up in direction children --> parents fHor->Cleanup(); fVer->Cleanup(); fMain->Cleanup(); delete fMain; } void multiembedded() { a = new MultiEmbeddedCanvas(gClient->GetRoot(), 1024, 768); }