#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include enum EMenuIds { M_FILE_NEW, M_FILE_CLOSE, M_FILE_EXIT, M_WINDOW_HOR, M_WINDOW_VERT, M_WINDOW_CASCADE, M_WINDOW_OPAQUE, M_WINDOW_ARRANGE, M_HELP_CONTENTS, M_HELP_ABOUT }; //---------------------------------------------------------------------- class TGAppMainFrame { RQ_OBJECT("TGAppMainFrame") protected: TGMainFrame *fMain; TGMdiMainFrame *fMainFrame; TGMdiMenuBar *fMenuBar; TGLayoutHints *fMenuBarItemLayout; TGPopupMenu *fMenuFile, *fMenuWindow, *fMenuHelp; TGPopupMenu *fMenuHisto; TRootEmbeddedCanvas *fEc; TCanvas *fCanvas; TH1F *fH1f; void InitMenu(); void CloseWindow(); public: TGAppMainFrame(const TGWindow *p, int w, int h); void HandleMenu(Int_t id); }; //---------------------------------------------------------------------- //______________________________________________________________________________ TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h) { fMain = new TGMainFrame(p, w, h, kVerticalFrame); fMenuBar = new TGMdiMenuBar(fMain, 10, 10); fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); fMainFrame = new TGMdiMainFrame(fMain, fMenuBar, 300, 300); fMain->AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); const TGPicture *pbg = gClient->GetPicture("mditestbg.xpm"); if (pbg) fMainFrame->GetContainer()->SetBackgroundPixmap(pbg->GetPicture()); TGMdiFrame *mdiFrame; ULong_t ic; mdiFrame = new TGMdiFrame(fMainFrame, 200, 200); mdiFrame->DontCallClose(); fEc = new TRootEmbeddedCanvas("glec", mdiFrame, 333, 180); mdiFrame->AddFrame(fEc, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5)); fCanvas = fEc->GetCanvas(); fCanvas->SetBorderMode(0); fCanvas->SetFillColor(0); fH1f = new TH1F("h1f","Test random numbers",200,0,10); fH1f->SetFillColor(45); mdiFrame->SetMdiHints(kMdiDefaultHints | kMdiHelp); mdiFrame->SetWindowName("Two"); mdiFrame->MapSubwindows(); mdiFrame->Layout(); mdiFrame->Move(150, 200); InitMenu(); fMain->SetWindowName("MDI test"); fMain->SetClassHints("mdi test", "mdi test"); if (pbg && pbg->GetWidth() > 600 && pbg->GetHeight() > 400) fMain->Resize(pbg->GetWidth(), pbg->GetHeight()+25); else fMain->Resize(640, 400); fMain->MapSubwindows(); fMain->MapWindow(); fMain->Layout(); } //______________________________________________________________________________ void TGAppMainFrame::HandleMenu(Int_t id) { // Handle menu items. switch (id) { case M_FILE_NEW: new TGMdiFrame(fMainFrame, 200, 100); break; case M_FILE_CLOSE: fMainFrame->Close(fMainFrame->GetCurrent()); break; case M_FILE_EXIT: CloseWindow(); break; case M_WINDOW_HOR: fMainFrame->TileHorizontal(); break; case M_WINDOW_VERT: fMainFrame->TileVertical(); break; case M_WINDOW_CASCADE: fMainFrame->Cascade(); break; case M_WINDOW_ARRANGE: fMainFrame->ArrangeMinimized(); break; case M_WINDOW_OPAQUE: if (fMenuWindow->IsEntryChecked(M_WINDOW_OPAQUE)) { fMenuWindow->UnCheckEntry(M_WINDOW_OPAQUE); fMainFrame->SetResizeMode(kMdiNonOpaque); } else { fMenuWindow->CheckEntry(M_WINDOW_OPAQUE); fMainFrame->SetResizeMode(kMdiOpaque); } break; case 1001: DrawHisto(); break; default: fMainFrame->SetCurrent(id); break; } } //______________________________________________________________________________ void TGAppMainFrame::DrawHisto() { TFormula *form1 = new TFormula("form1","abs(sin(x)/x)"); TF1 *sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10); sqroot->SetParameters(10,4,1,20); fCanvas->cd(); // or: // TCanvas *c1 = fEc->GetCanvas(); // c1->cd(); fH1f->FillRandom("sqroot",10000); fH1f->Draw(); fCanvas->Update(); // or: // c1->Update(); } //______________________________________________________________________________ void TGAppMainFrame::InitMenu() { fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); fMenuFile = new TGPopupMenu(gClient->GetRoot()); fMenuFile->AddEntry(new TGHotString("&New Window"), M_FILE_NEW); fMenuFile->AddEntry(new TGHotString("&Close Window"), M_FILE_CLOSE); fMenuFile->AddSeparator(); fMenuFile->AddEntry(new TGHotString("E&xit"), M_FILE_EXIT); fMenuWindow = new TGPopupMenu(gClient->GetRoot()); fMenuWindow->AddEntry(new TGHotString("Tile &Horizontally"), M_WINDOW_HOR); fMenuWindow->AddEntry(new TGHotString("Tile &Vertically"), M_WINDOW_VERT); fMenuWindow->AddEntry(new TGHotString("&Cascade"), M_WINDOW_CASCADE); fMenuWindow->AddSeparator(); fMenuWindow->AddPopup(new TGHotString("&Windows"), fMainFrame->GetWinListMenu()); fMenuWindow->AddSeparator(); fMenuWindow->AddEntry(new TGHotString("&Arrange icons"), M_WINDOW_ARRANGE); fMenuWindow->AddSeparator(); fMenuWindow->AddEntry(new TGHotString("&Opaque resize"), M_WINDOW_OPAQUE); fMenuWindow->CheckEntry(M_WINDOW_OPAQUE); fMenuHisto = new TGPopupMenu(gClient->GetRoot()); fMenuHisto->AddEntry(new TGHotString("&Draw..."), 1001); fMenuHelp = new TGPopupMenu(gClient->GetRoot()); fMenuHelp->AddEntry(new TGHotString("&Contents"), M_HELP_CONTENTS); fMenuHelp->AddSeparator(); fMenuHelp->AddEntry(new TGHotString("&About"), M_HELP_ABOUT); fMenuHelp->DisableEntry(M_HELP_CONTENTS); fMenuHelp->DisableEntry(M_HELP_ABOUT); // menu message are handled by the class' HandleMenu() method fMenuFile->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); fMenuWindow->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); fMenuHisto->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); fMenuHelp->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); fMenuBar->AddPopup(new TGHotString("&File"), fMenuFile, fMenuBarItemLayout); fMenuBar->AddPopup(new TGHotString("&Windows"),fMenuWindow,fMenuBarItemLayout); fMenuBar->AddPopup(new TGHotString("&Histo"),fMenuHisto,fMenuBarItemLayout); fMenuBar->AddPopup(new TGHotString("&Help"), fMenuHelp, fMenuBarItemLayout); } //______________________________________________________________________________ void TGAppMainFrame::CloseWindow() { gApplication->Terminate(0); } //---------------------------------------------------------------------- void mdisimple() { new TGAppMainFrame(0, 640, 400); } //---------------------------------------------------------------------- #ifdef STANDALONE int main(int argc, char **argv) { TApplication theApp("MdiTest", &argc, argv); mditest(); theApp.Run(); return 0; } #endif