Logo ROOT  
Reference Guide
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
18class MyMainFrame : public TGMainFrame {
19
20private:
21 TGCompositeFrame *fCframe;
22 TGTextButton *fStart, *fPause, *fExit;
23 Bool_t start, pause;
24
25public:
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
35void 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
51void 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
67MyMainFrame::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
100MyMainFrame::~MyMainFrame()
101{
102 // Clean up all widgets, frames and layouthints that were used
103 fCframe->Cleanup();
104 Cleanup();
105}
106
107
108void buttonChangelabel()
109{
110 // Popup the GUI...
111 new MyMainFrame(gClient->GetRoot(), 350, 80);
112}
@ kFixedWidth
Definition: GuiTypes.h:387
@ kHorizontalFrame
Definition: GuiTypes.h:382
#define h(i)
Definition: RSha256.hxx:106
unsigned int UInt_t
Definition: RtypesCore.h:44
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassDef(name, id)
Definition: Rtypes.h:322
@ kButtonDown
Definition: TGButton.h:54
@ kButtonUp
Definition: TGButton.h:53
#define gClient
Definition: TGClient.h:166
@ kLHintsCenterX
Definition: TGLayout.h:32
@ kLHintsTop
Definition: TGLayout.h:34
@ kLHintsExpandX
Definition: TGLayout.h:37