#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const char *WindTitle[2] = {"Speed", "Direction"}; enum ETestCommandIdentifiers { M_FILE_EXIT, }; void ltest() { new TestMainFrame( gClient->GetRoot(), 400,200); } class TestMainFrame : public TGMainFrame{ RQ_OBJECT("TestMainFrame") private: TGMenuBar *fMenuBar; TGPopupMenu *fMenuFile; TGLayoutHints *fMenuBarLayout, *fMenuBarItemLayout; TGFont *myfont; TGGC myGC; TGLabel *WindLabel[2]; public: TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h); virtual ~TestMainFrame(); void MakeALabel(); void MakeALabel1(); // slots void CloseWindow(); void HandleMenu(Int_t id); void HandlePopup() { printf("menu popped up\n"); } void HandlePopdown() { printf("menu popped down\n"); } void Created() { Emit("Created()"); } //*SIGNAL* void Welcome() { printf("TestMainFrame has been created. Welcome!\n"); } }; TestMainFrame::TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame( p, w, h) { static char *UseThisFont = "-adobe-helvetica-bold-r-*-*-14-*-*-*-*-*-iso8859-1"; Pixel_t Wind; // Create test main frame. A TGMainFrame is a top level window. Connect("CloseWindow()", "TestMainFrame", this, "CloseWindow()"); // Create menubar and popup menus. The hint objects are used to place // and group the different menu widgets with respect to eachother. fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1); fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight); fMenuFile = new TGPopupMenu(p); fMenuFile->AddSeparator(); fMenuFile->AddEntry("E&xit", M_FILE_EXIT); // Menu button messages are handled by the main frame (i.e. "this") // HandleMenu() method. fMenuFile->Connect("Activated(Int_t)", "TestMainFrame", this, "HandleMenu(Int_t)"); fMenuFile->Connect("PoppedUp()", "TestMainFrame", this, "HandlePopup()"); fMenuFile->Connect("PoppedDown()", "TestMainFrame", this, "HandlePopdown()"); fMenuBar = new TGMenuBar( this, 1, 1, kHorizontalFrame); fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout); AddFrame(fMenuBar, fMenuBarLayout); SetWindowName("GuiTest Signal/Slots"); MakeALabel(); MapSubwindows(); Resize(); MapWindow(); Connect("Created()", "TestMainFrame", this, "Welcome()"); Created(); } TestMainFrame::~TestMainFrame() { // Delete all created widgets. delete fTestButton; delete fTestText; delete fStatusFrame; delete fContainer; delete fCanvasWindow; delete fMenuBarLayout; delete fMenuBarItemLayout; delete fMenuBarHelpLayout; delete fMenuBar; delete fMenuFile; delete fMenuTest; delete fMenuHelp; delete fCascadeMenu; delete fCascade1Menu; delete fCascade2Menu; delete fMenuNew1; delete fMenuNew2; } void TestMainFrame::MakeALabel1() { Pixel_t Wind; TGCompositeFrame *TBFrame = new TGCompositeFrame(this, 10, 10, kHorizontalFrame); // // SEtup a group frame. // gClient->GetColorByName("blue", Wind); TBFrame->ChangeBackground( Wind); TGLayoutHints *lhframes = new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 5,2,2,2); TGGroupFrame *WindFrame = new TGGroupFrame(TBFrame, "Wind", kHorizontalFrame); WindFrame->SetLayoutManager(new TGMatrixLayout(WindFrame, 2, 2, 2)); WindFrame->ChangeBackground( Wind); TBFrame->AddFrame( WindFrame, lhframes); label = new TGLabel( WindFrame, WindTitle[0]); label->ChangeBackground( Wind); label->SetTextJustify(kTextCenterX|kTextCenterY); WindFrame->AddFrame( label, lhframes); label = new TGLabel( WindFrame, WindTitle[1]); label->ChangeBackground( Wind); label->SetTextJustify(kTextCenterX|kTextCenterY); WindFrame->AddFrame( label, lhframes); WindLabel[0] = new TGLabel (WindFrame, WindTitle[0]); WindLabel[0]->ChangeBackground( Wind); WindLabel[0]->SetText("N/A"); WindLabel[0]->SetTextJustify(kTextCenterX|kTextCenterY); WindFrame->AddFrame( WindLabel[0]); WindLabel[1] = new TGLabel (WindFrame, WindTitle[1]); WindLabel[1]->ChangeBackground( Wind); WindLabel[1]->SetText("N/A"); WindLabel[1]->SetTextJustify(kTextCenterX|kTextCenterY); WindFrame->AddFrame( WindLabel[1], lhframes); AddFrame( TBFrame, lhframes); } void TestMainFrame::MakeALabel() { Pixel_t Wind; // Get the font for the frame etc from the TGClient class. myGC = *fClient->GetResourcePool()->GetFrameGC(); myfont = fClient->GetFont(UseThisFont); if (myfont) myGC.SetFont(myfont->GetFontHandle()); TGCompositeFrame *TBFrame = new TGCompositeFrame(this, 10, 10, kHorizontalFrame); TBFrame->ChangeBackground(kBlack); // // SEtup a group frame. // gClient->GetColorByName("blue", Wind); TGLayoutHints *lhframes = new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 5,2,2,2); TGGroupFrame *WindFrame = new TGGroupFrame(TBFrame, "Wind", kHorizontalFrame, myGC(), myfont->GetFontStruct()); WindFrame->SetLayoutManager(new TGMatrixLayout(WindFrame, 2, 2, 2)); WindFrame->ChangeBackground( Wind); TBFrame->AddFrame( WindFrame, lhframes); label = new TGLabel( WindFrame, WindTitle[0], myGC(), myfont->GetFontStruct(), kChildFrame, Wind); label->SetTextJustify(kTextCenterX|kTextCenterY); ToClean->Add(label); WindFrame->AddFrame( label, lhframes); label = new TGLabel( WindFrame, WindTitle[1], myGC(), myfont->GetFontStruct(), kChildFrame, Wind); label->SetTextJustify(kTextCenterX|kTextCenterY); ToClean->Add(label); WindFrame->AddFrame( label, lhframes); WindLabel[0] = new TGLabel (WindFrame, WindTitle[0], myGC(), myfont->GetFontStruct(), kChildFrame, Wind); WindLabel[0]->SetText("N/A"); WindLabel[0]->SetTextJustify(kTextCenterX|kTextCenterY); ToClean->Add(WindLabel[0]); WindFrame->AddFrame( WindLabel[0]); WindLabel[1] = new TGLabel (WindFrame, WindTitle[1], myGC(), myfont->GetFontStruct(), kChildFrame, Wind); WindLabel[1]->SetText("N/A"); WindLabel[1]->SetTextJustify(kTextCenterX|kTextCenterY); ToClean->Add(WindLabel[0]); WindFrame->AddFrame( WindLabel[1], lhframes); } void TestMainFrame::CloseWindow() { // Got close message for this MainFrame. Terminates the application. gApplication->Terminate(0); } void TestMainFrame::HandleMenu(Int_t id) { // Handle menu items. switch (id) { case M_FILE_EXIT: CloseWindow(); // terminate theApp no need to use SendCloseMessage() break; default: printf("Menu item %d selected\n", id); break; } }