/****************************************************************************** * File: multican.C * * Description: macro file to test embedded canvas * * This macro gives an example of how to select a canvas from * * the combo box list and show it via the embedded canvas * * widget * * Author: Ilka Antcheva (CERN/PH/SFT) * *Site Contact: roottalk@cern.ch * *ROOT Version: 4.01/05 * * Last Change: 06/12/2004 * ******************************************************************************/ #include #include #include #include #include #include class TestFrame { RQ_OBJECT("TestFrame") private: TGMainFrame *fMain; TRootEmbeddedCanvas *fEcan; public: TestFrame(const TGWindow *p, UInt_t w, UInt_t h); virtual ~TestFrame(); // slots void DoSelection(); }; void TestFrame::DoSelection(Int_t id) { // Select a canvas from the list. Printf("Select a canvas from the list..."); switch(id) { case 0: { fEcan->GetCanvas()->Clear(); fEcan->GetCanvas()->Range(0,0,1,1); fEcan->GetCanvas()->SetBorderSize(2); fEcan->GetCanvas()->SetFrameFillColor(0); fEcan->GetCanvas()->cd(); ellipse1 = new TEllipse(0.25,0.6,0.2,0.1,0,360,0); ellipse1->SetFillColor(6); ellipse1->SetFillStyle(3008); ellipse1->Draw(); break; } case 1: { fEcan->GetCanvas()->Clear(); fEcan->GetCanvas()->Range(0,0,1,1); fEcan->GetCanvas()->SetBorderSize(2); fEcan->GetCanvas()->SetFrameFillColor(0); fEcan->GetCanvas()->cd(); ellipse2 = new TEllipse(0.75,0.6,0.2,0.1,45,315,0); ellipse2->SetFillColor(2); ellipse2->SetLineColor(4); ellipse2->Draw(); break; } case 2: { fEcan->GetCanvas()->Clear(); fEcan->GetCanvas()->Range(0,0,1,1); fEcan->GetCanvas()->SetBorderSize(2); fEcan->GetCanvas()->SetFrameFillColor(0); fEcan->GetCanvas()->cd(); ellipse3 = new TEllipse(0.75,0.25,0.2,0.15,45,315,62); ellipse3->SetFillColor(5); ellipse3->SetLineColor(4); ellipse3->SetLineWidth(6); ellipse3->Draw(); break; } } gPad = fEcan->GetCanvas(); gPad->Modified(); gPad->Update(); } TestFrame::TestFrame(const TGWindow *p, UInt_t w, UInt_t h) { // Create a main frame fMain = new TGMainFrame(p, w, h); // Create an embedded canvas and add it to the main frame fEcan = new TRootEmbeddedCanvas ("ECanvas", fMain, 300, 300); fMain->AddFrame (fEcan, new TGLayoutHints (kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10)); fEcan->GetCanvas()->Range(0,0,1,1); fEcan->GetCanvas()->SetBorderSize(2); fEcan->GetCanvas()->SetFrameFillColor(0); fEcan->GetCanvas()->cd(); // Create a horizontal frame containing a combo box and two text buttons TGHorizontalFrame *fHor = new TGHorizontalFrame(fMain, 10, 5); TGComboBox *fCombo = new TGComboBox(fHor, 98); Int_t fFirstEntry = 0; Int_t fLastEntry = 3; char tmp[20]; for (int i = fFirstEntry; i < fLastEntry; i++) { sprintf(tmp, "Canvas %i", i+1); fCombo->AddEntry(tmp, i); } fCombo->Connect("Selected(Int_t)", "TestFrame", this, "DoSelection(Int_t)"); fCombo->Resize(120, 20); fCombo->Select(2); fHor->AddFrame(fCombo, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5)); 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 | kLHintsLeft, 200, 5, 5, 5)); fMain->AddFrame(fHor, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5)); // Set a name to the main frame fMain->SetWindowName("Test of Canvas Selection"); fMain->MapSubwindows(); //initialize the layout algorithm via Resize() fMain->Resize(fMain->GetDefaultSize()); // Give min and max window size + a step of x,y incrementing between the given sizes fMain->SetWMSizeHints(350, 350, 700, 700, 0, 0); // Map main frame fMain->MapWindow(); } TestFrame::~TestFrame() { // Clean up in direction children --> parents fHor->Cleanup(); fMain->Cleanup(); delete fMain; } void multican() { new TestFrame(gClient->GetRoot(), 400, 500); }