ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
buttonChangelabel.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// This macro gives an example for changing text button labels anytime the Start or Pause buttons are clicked.
4 /// To run it do either:
5 /// ~~~
6 /// .x buttonChangelabel.C
7 /// .x buttonChangelabel.C++
8 /// ~~~
9 ///
10 /// \macro_code
11 ///
12 /// \author Ilka Antcheva 1/12/2006
13 
14 #include <TGClient.h>
15 #include <TGButton.h>
16 #include <TGFrame.h>
17 
18 class MyMainFrame : public TGMainFrame {
19 
20 private:
21  TGCompositeFrame *fCframe;
22  TGTextButton *fStart, *fPause, *fExit;
23  Bool_t start, pause;
24 
25 public:
26  MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
27  virtual ~MyMainFrame();
28  // slots
29  void ChangeStartLabel();
30  void ChangePauseLabel();
31 
32  ClassDef(MyMainFrame, 0)
33 };
34 
35 void MyMainFrame::ChangeStartLabel()
36 {
37  // Slot connected to the Clicked() signal.
38  // It will toggle labels "Start" and "Stop".
39 
40  fStart->SetState(kButtonDown);
41  if (!start) {
42  fStart->SetText("&Stop");
43  start = kTRUE;
44  } else {
45  fStart->SetText("&Start");
46  start = kFALSE;
47  }
48  fStart->SetState(kButtonUp);
49 }
50 
51 void MyMainFrame::ChangePauseLabel()
52 {
53  // Slot connected to the Clicked() signal.
54  // It will toggle labels "Resume" and "Pause".
55 
56  fPause->SetState(kButtonDown);
57  if (!pause) {
58  fPause->SetText("&Resume");
59  pause = kTRUE;
60  } else {
61  fPause->SetText("&Pause");
62  pause = kFALSE;
63  }
64  fPause->SetState(kButtonUp);
65 }
66 
67 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
68  TGMainFrame(p, w, h)
69 {
70  // Create a horizontal frame containing buttons
71  fCframe = new TGCompositeFrame(this, 170, 20, kHorizontalFrame|kFixedWidth);
72 
73  fStart = new TGTextButton(fCframe, "&Start");
74  fStart->Connect("Clicked()", "MyMainFrame", this, "ChangeStartLabel()");
75  fCframe->AddFrame(fStart, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
76  3, 2, 2, 2));
77  fStart->SetToolTipText("Click to toggle the button label (Start/Stop)");
78  start = kFALSE;
79 
80  fPause = new TGTextButton(fCframe, "&Pause");
81  fPause->Connect("Clicked()", "MyMainFrame", this, "ChangePauseLabel()");
82  fPause->SetToolTipText("Click to toggle the button label (Pause/Resume)");
83  fCframe->AddFrame(fPause, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
84  3, 2, 2, 2));
85  pause = kFALSE;
86 
87  AddFrame(fCframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
88 
89  fExit = new TGTextButton(this, "&Exit ","gApplication->Terminate(0)");
90  AddFrame(fExit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,5,5,2,2));
91 
92  SetWindowName("Change Labels");
93 
94  MapSubwindows();
95  Resize(GetDefaultSize());
96  MapWindow();
97 }
98 
99 
100 MyMainFrame::~MyMainFrame()
101 {
102  // Clean up all widgets, frames and layouthints that were used
103  fCframe->Cleanup();
104  Cleanup();
105 }
106 
107 
108 void buttonChangelabel()
109 {
110  // Popup the GUI...
111  new MyMainFrame(gClient->GetRoot(), 350, 80);
112 }
#define gClient
Definition: TGClient.h:174
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
#define ClassDef(name, id)
Definition: Rtypes.h:254
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kTRUE
Definition: Rtypes.h:91