/******************************************************************************
 *        File:   number.C                                                    *
 * Description:   signals/slots example                                       *
 *                This macro gives an example of how to update a label        *
 *                according to the changed value of a number entry            *
 *      Author:   Ilka Antcheva (CERN/PH/SFT)                                 *
 *Site Contact:   roottalk@cern.ch                                            *
 *ROOT Version:   5.03/01                                                     *
 * Last Change:   01/09/2005                                                  *
 ******************************************************************************/

#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TString.h>

class MyDialog : public TGMainFrame {

private:
   TGCompositeFrame    *fHor1;
   TGTextButton        *fClose;
   TGGroupFrame        *fGframe;
   TGNumberEntry       *fNumber;
   TGLabel             *fLabel;

public:
   MyDialog(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyDialog();
   void DoSetlabel();
   
   ClassDef(MyDialog, 0)
};
                          
MyDialog::MyDialog(const TGWindow *p, UInt_t w, UInt_t h)
   : TGMainFrame(p, w, h)
{
   // 1st: to create an window with respect to its parent (main) window

   fHor1 = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
   fClose = new TGTextButton(fHor1, "Close", "gApplication->Terminate(0)");
   fHor1->AddFrame(fClose, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
                                         4, 4, 4, 4));
   AddFrame(fHor1,new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1));
	
   // 2nd: create widgets in the dialog
   fNumber = new TGNumberEntry(this, 0, 9,999, TGNumberFormat::kNESInteger,
                                       TGNumberFormat::kNEANonNegative, 
                                       TGNumberFormat::kNELLimitMinMax, 0, 99999);
   fNumber->Connect("ValueSet(Long_t)", "MyDialog", this, "DoSetlabel()");
   (fNumber->GetNumberEntry())->Connect("ReturnPressed()", "MyDialog", this, "DoSetlabel()");
   AddFrame(fNumber, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
   fGframe = new TGGroupFrame(this, "Value");
   fLabel = new TGLabel(fGframe, "No input.");
   fGframe->AddFrame(fLabel, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
   AddFrame(fGframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 1, 1));

   MapSubwindows();
   Resize(GetDefaultSize());

   SetWindowName("Example");

    MapWindow();
}

MyDialog::~MyDialog()
{
   delete fNumber;
   delete fLabel;
   delete fClose;
   delete fHor1; 
   delete fGframe; 
}

void MyDialog::DoSetlabel()
{
   fLabel->SetText(Form("%d",fNumber->GetNumberEntry()->GetIntNumber()));
   fGframe->Layout();
}

void number()
{
	new MyDialog(gClient->GetRoot(), 50, 50); 
}

//	---------------   main program   ---------------------
int main(int argc, char **argv)
{
   TApplication theApp("App", &argc, argv);
   number();
   theApp.Run();
		
   return 0;
}


