buttonChangelabel.C

Go to the documentation of this file.
00001 //
00002 // Author: Ilka Antcheva   1/12/2006
00003 
00004 // This macro gives an example for changing text button labels anytime
00005 // the Start or Pause buttons are clicked.
00006 // To run it do either:
00007 // .x buttonChangelabel.C
00008 // .x buttonChangelabel.C++
00009 
00010 #include <TGClient.h>
00011 #include <TGButton.h>
00012 #include <TGFrame.h>
00013 
00014 class MyMainFrame : public TGMainFrame {
00015 
00016 private:
00017    TGCompositeFrame *fCframe;
00018    TGTextButton     *fStart, *fPause, *fExit;
00019    Bool_t            start, pause;
00020 
00021 public:
00022    MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
00023    virtual ~MyMainFrame();
00024    // slots
00025    void ChangeStartLabel();
00026    void ChangePauseLabel();
00027 
00028    ClassDef(MyMainFrame, 0)
00029 };
00030 
00031 void MyMainFrame::ChangeStartLabel()
00032 {
00033   // Slot connected to the Clicked() signal. 
00034   // It will toggle labels "Start" and "Stop".
00035   
00036   fStart->SetState(kButtonDown);
00037   if (!start) {
00038      fStart->SetText("&Stop");
00039      start = kTRUE;
00040   } else {
00041      fStart->SetText("&Start");
00042      start = kFALSE;
00043   }
00044   fStart->SetState(kButtonUp);
00045 }
00046 
00047 void MyMainFrame::ChangePauseLabel()
00048 {
00049   // Slot connected to the Clicked() signal. 
00050   // It will toggle labels "Resume" and "Pause".
00051   
00052   fPause->SetState(kButtonDown);
00053   if (!pause) {
00054      fPause->SetText("&Resume");
00055      pause = kTRUE;
00056   } else {
00057      fPause->SetText("&Pause");
00058      pause = kFALSE;
00059   }
00060   fPause->SetState(kButtonUp);
00061 }
00062 
00063 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
00064   TGMainFrame(p, w, h)
00065 {
00066    // Create a horizontal frame containing buttons
00067    fCframe = new TGCompositeFrame(this, 170, 20, kHorizontalFrame|kFixedWidth);
00068    
00069    fStart = new TGTextButton(fCframe, "&Start");
00070    fStart->Connect("Clicked()", "MyMainFrame", this, "ChangeStartLabel()");
00071    fCframe->AddFrame(fStart, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 
00072                                                3, 2, 2, 2));
00073    fStart->SetToolTipText("Click to toggle the button label (Start/Stop)");
00074    start = kFALSE;
00075    
00076    fPause = new TGTextButton(fCframe, "&Pause");
00077    fPause->Connect("Clicked()", "MyMainFrame", this, "ChangePauseLabel()");
00078    fPause->SetToolTipText("Click to toggle the button label (Pause/Resume)");
00079    fCframe->AddFrame(fPause, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00080                                                3, 2, 2, 2));
00081    pause = kFALSE;
00082    
00083    AddFrame(fCframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
00084 
00085    fExit = new TGTextButton(this, "&Exit ","gApplication->Terminate(0)");
00086    AddFrame(fExit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,5,5,2,2));
00087    
00088    SetWindowName("Change Labels");
00089    
00090    MapSubwindows();
00091    Resize(GetDefaultSize());
00092    MapWindow();
00093 }
00094 
00095 
00096 MyMainFrame::~MyMainFrame()
00097 {
00098    // Clean up all widgets, frames and layouthints that were used
00099    fCframe->Cleanup();
00100    Cleanup();
00101 }
00102 
00103 
00104 void buttonChangelabel()
00105 {
00106    // Popup the GUI...
00107    new MyMainFrame(gClient->GetRoot(), 350, 80);
00108 }

Generated on Tue Jul 5 15:44:22 2011 for ROOT_528-00b_version by  doxygen 1.5.1