/****************************************************************************** * File: dialog.C * * Description: example macro file * * This macro gives an example of how to enter a histogram * * name in a text entry widgets via a dialog window and how * * to draw this histogram in an embedded canvas * * Author: Ilka Antcheva (CERN/PH/SFT) * *Site Contact: roottalk@cern.ch * *ROOT Version: 4.03/03 * * Last Change: 9/02/2006 * ******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include class MyDialog { RQ_OBJECT("MyDialog") private: TGTransientFrame *fMain; //dialog window TGCompositeFrame *fHor1; //container farme TGTextButton *fClose; //close button TGNumberEntry *fMass; //text entry for user input TGLabel *fLabel; //label, used for feedback info public: MyDialog(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h); virtual ~MyDialog(); // slots void CloseWindow(); void DoClose(); void DoSetMass(); }; MyDialog::MyDialog(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h) { // 1st: to create an window with respect to its parent (main) window fMain = new TGTransientFrame(p, main, w, h); fMain->Connect("CloseWindow()", "MyDialog", this, "CloseWindow()"); fHor1 = new TGHorizontalFrame(fMain, 50, 20, kFixedWidth); fClose = new TGTextButton(fHor1, "Close", 1); fClose->Connect("Clicked()", "MyDialog", this, "DoClose()"); fHor1->Resize(200, fClose->GetDefaultHeight()); fHor1->AddFrame(fClose, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 4, 4, 4, 4)); fMain->AddFrame(fHor1,new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1)); // 2nd: create widgets in the dialog fMass = new TGNumberEntry(fMain, 0, 5, 999, TGNumberFormat::kNESInteger); fMass->GetNumberEntry()->SetToolTipText("Enter the mass you would like to study"); fMain->AddFrame(fMass, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 10, 10, 10)); fMass->GetNumberEntry()->Connect("ReturnPressed()", "MyDialog", this, "DoSetMass()"); fMass->Connect("ValueSet(Long_t)", "MyDialog", this, "DoSetMass()"); fLabel = new TGLabel(fMain, "No value set."); fMain->AddFrame(fLabel, new TGLayoutHints(kLHintsTop | kLHintsLeft, 15, 15, 15, 15)); fMain->MapSubwindows(); fMain->Resize(fMain->GetDefaultSize()); // position of the dialog relative to the parent's window Window_t wdum; int ax, ay; gVirtualX->TranslateCoordinates(main->GetId(), fMain->GetParent()->GetId(), (Int_t)(((TGFrame *) main)->GetWidth() - fMain->GetWidth()) >> 1, (Int_t)(((TGFrame *) main)->GetHeight() - fMain->GetHeight()) >> 1, ax, ay, wdum); fMain->Move(ax, ay); fMain->SetWindowName("Select Mass"); fMain->MapWindow(); } MyDialog::~MyDialog() { delete fMass; delete fLabel; delete fClose; delete fHor1; delete fMain; } void MyDialog::CloseWindow() { // Called when the window is closed via the window manager. delete this; } void MyDialog::DoSetMass() { gMass = (Int_t)fMass->GetNumber(); fLabel->SetText(Form("Seleced: %d",gMass)); gClient->NeedRedraw(fMain); } void MyDialog::DoClose() { printf("\nThe Close button is pressed\n"); fMain->SendCloseMessage(); } void dialog() { new MyDialog(gClient->GetRoot(), gClient->GetRoot(), 200, 200); } // --------------- main program --------------------- int main(int argc, char **argv) { TApplication theApp("App", &argc, argv); dialog(); theApp.Run(); return 0; }