#include #include #include namespace TestEnv { const unsigned short InitialMainWidth = 700; const unsigned short InitialMainHeight = 500; const unsigned short BoxWidth = 400; const unsigned short BoxHeight = 400; const unsigned int MyColor = 0x00FF00; class TestGraphics { private: TGMdiMainFrame MainFrame; TGMdiFrame * MdiFrame; TGCanvas * Canvas; TGContainer * Container; public: TestGraphics () : MainFrame (gClient->GetRoot (), NULL, InitialMainWidth, InitialMainHeight), MdiFrame (NULL), Canvas (NULL) { MainFrame.Resize (); Redraw (); MdiFrame = new TGMdiFrame (&MainFrame, BoxWidth, BoxHeight, kVerticalFrame); MdiFrame->DontCallClose (); // The next statement causes the following error to be displayed: // Error in : canvas container must inherit from TGCompositeFrame // What is wrong? // Anyhow, it works without using AddFrame, as well. Where is AddFrame used for? // MainFrame.AddFrame (MdiFrame); Redraw (); Canvas = new TGCanvas (MdiFrame); TGContainer *const Container = new TGContainer (Canvas); Container->SetBackgroundColor (MyColor); Container->fMapSubwindows = true; Container->SetLayoutManager (new TGMatrixLayout (Container, 0, 3)); MdiFrame->AddFrame (Canvas, new TGLayoutHints (kLHintsExpandX | kLHintsExpandY)); MdiFrame->SetWindowName ("MdiFrame name"); // It is not clear which calls are needed exactly in case a component // is added, removed or changed on the Canvas, to make the change // visible. The following works in many cases, although sometimes it // becomes visible only after moving or resizing the window with the mouse. MdiFrame->Layout (); MdiFrame->MapSubwindows (); MdiFrame->MapWindow (); MdiFrame->Resize (); Redraw (); // At this point a "segmentation violation" is reported repeatedly // when the mouse is moved over the green area of the Canvas. It seems // this is caused in TGContainer::HandleMotion (). } void Redraw () { // A function to make the changes in the main frame and its sub-frames // visible. It is not clear what is the official way to do this. The // following calls work in most cases, although sometimes only after // moving or resizing the window. MainFrame.Layout (); MainFrame.MapSubwindows (); MainFrame.MapWindow (); } virtual ~TestGraphics () { MdiFrame->Cleanup (); MdiFrame->DeleteWindow (); } ClassDef(TestGraphics, 1); }; } // End of namespace ClassImp (TestEnv::TestGraphics);