From $ROOTSYS/tutorials/gui/buttonTest.C

// Author: Valeriy Onuchin   17/07/2007
//
// This macro gives an example of how to set/change text button attributes. 
//
// To run it do either:
// .x buttonTest.C
// .x buttonTest.C++

#include <TGButton.h>
#include <TGButtonGroup.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TG3DLine.h>
#include <TApplication.h>



//////////// auxilary class ///////////////////////////////////////////////////
class TextMargin : public TGHorizontalFrame {

protected:
   TGNumberEntry *fEntry;

public:
   TextMargin(const TGWindow *p, const char *name) : TGHorizontalFrame(p) 
   {
      fEntry = new TGNumberEntry(this, 0, 6, -1, TGNumberFormat::kNESInteger);
      AddFrame(fEntry, new TGLayoutHints(kLHintsLeft));
      TGLabel *label = new TGLabel(this, name);
      AddFrame(label, new TGLayoutHints(kLHintsLeft, 10));
   }
   TGTextEntry *GetEntry() const { return fEntry->GetNumberEntry(); }

   ClassDef(TextMargin, 0)
};

////////////////////////////////////////////////////////////////////////////////
class ButtonWindow : public TGMainFrame {

protected:
   TGTextButton *fButton;   // button being tested
   
public:
   ButtonWindow();
   void DoHPosition(Int_t);
   void DoVPosition(Int_t);
   void DoLeftMargin(char*);
   void DoRightMargin(char*);
   void DoTopMargin(char*);
   void DoBottomMargin(char*);
   
   ClassDef(ButtonWindow, 0)
};


//______________________________________________________________________________
ButtonWindow::ButtonWindow() : TGMainFrame(gClient->GetRoot(), 10, 10, kHorizontalFrame)
{
   // Main test window.

   SetCleanup(kDeepCleanup);

   // Controls on right
   TGVerticalFrame *controls = new TGVerticalFrame(this);
   AddFrame(controls, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 
                                        5, 5, 5, 5));

   // Separator
   TGVertical3DLine *separator = new TGVertical3DLine(this);
   AddFrame(separator, new TGLayoutHints(kLHintsRight | kLHintsExpandY));

   // Contents
   TGHorizontalFrame *contents = new TGHorizontalFrame(this);
   AddFrame(contents, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5));

   // The button for test
   fButton = new TGTextButton(contents,
      "&This button has a multi-line label\nand shows features\n"
      "available in the button classes");
   fButton->Resize(300, 200);
   fButton->ChangeOptions(fButton->GetOptions() | kFixedSize);
   fButton->SetToolTipText("The assigned tooltip\ncan be multi-line also",200);
   contents->AddFrame(fButton, new TGLayoutHints(kLHintsCenterX|kLHintsCenterY,
                      20, 20, 20, 20));

   TGGroupFrame *group = new TGGroupFrame(controls, "Enable/Disable");
   group->SetTitlePos(TGGroupFrame::kCenter);
   TGCheckButton *disable = new TGCheckButton(group, "Switch state\nEnable/Disable");
   disable->SetOn();
   disable->Connect("Toggled(Bool_t)", "TGButton", fButton, "SetEnabled(Bool_t)");
   group->AddFrame(disable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
   controls->AddFrame(group, new TGLayoutHints(kLHintsExpandX));


   // control horizontal position of the text
   TGButtonGroup *horizontal = new TGButtonGroup(controls, "Horizontal Position");
   horizontal->SetTitlePos(TGGroupFrame::kCenter);
   new TGRadioButton(horizontal, "Center", kTextCenterX);
   new TGRadioButton(horizontal, "Left", kTextLeft);
   new TGRadioButton(horizontal, "Right", kTextRight);
   horizontal->SetButton(kTextCenterX);
   horizontal->Connect("Pressed(Int_t)", "ButtonWindow", this, 
                       "DoHPosition(Int_t)");
   controls->AddFrame(horizontal, new TGLayoutHints(kLHintsExpandX));


   // control vertical position of the text
   TGButtonGroup *vertical = new TGButtonGroup(controls, "Vertical Position");
   vertical->SetTitlePos(TGGroupFrame::kCenter);
   new TGRadioButton(vertical, "Center", kTextCenterY);
   new TGRadioButton(vertical, "Top", kTextTop);
   new TGRadioButton(vertical, "Bottom", kTextBottom);
   vertical->SetButton(kTextCenterY);
   vertical->Connect("Pressed(Int_t)", "ButtonWindow", this, 
                     "DoVPosition(Int_t)");
   controls->AddFrame(vertical, new TGLayoutHints(kLHintsExpandX));


   // control margins of the text
   TGGroupFrame *margins = new TGGroupFrame(controls, "Text Margins");
   margins->SetTitlePos(TGGroupFrame::kCenter);

   TextMargin *left = new TextMargin(margins, "Left");
   margins->AddFrame(left, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
   left->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
                             this, "DoLeftMargin(char*)");

   TextMargin *right = new TextMargin(margins, "Right");
   margins->AddFrame(right, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
   right->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
                               this, "DoRightMargin(char*)");

   TextMargin *top = new TextMargin(margins, "Top");
   margins->AddFrame(top, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
   top->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
                             this, "DoTopMargin(char*)");

   TextMargin *bottom = new TextMargin(margins, "Bottom");
   margins->AddFrame(bottom, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
   bottom->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
                               this, "DoBottomMargin(char*)");

   controls->AddFrame(margins, new TGLayoutHints(kLHintsExpandX));

   TGTextButton *quit = new TGTextButton(controls, "Quit");
   controls->AddFrame(quit, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
                                              0, 0, 0, 5));
   quit->Connect("Pressed()", "TApplication", gApplication, "Terminate()");

   Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
   DontCallClose();

   MapSubwindows();
   Resize();

   SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), 1000, 1000, 0 ,0);
   SetWindowName("Button Test");
   MapRaised();
}

//______________________________________________________________________________
void ButtonWindow::DoHPosition(Int_t id)
{
   // Horizontal position handler.

   Int_t tj = fButton->GetTextJustify();
   tj &= ~kTextCenterX;
   tj &= ~kTextLeft;
   tj &= ~kTextRight;
   tj |= id;
   fButton->SetTextJustify(tj);
}

//______________________________________________________________________________
void ButtonWindow::DoVPosition(Int_t id)
{
   // Vertical position handler.

   Int_t tj = fButton->GetTextJustify();

   tj &= ~kTextCenterY;
   tj &= ~kTextTop;
   tj &= ~kTextBottom;
   tj |= id;
   fButton->SetTextJustify(tj);
}

//______________________________________________________________________________
void ButtonWindow::DoLeftMargin(char *val)
{
   // Set left text margin.

   fButton->SetLeftMargin(atoi(val));
   gClient->NeedRedraw(fButton);
}  

//______________________________________________________________________________
void ButtonWindow::DoRightMargin(char *val)
{
   // Set right text margin.

   fButton->SetRightMargin(atoi(val));
   gClient->NeedRedraw(fButton);
}

//______________________________________________________________________________
void ButtonWindow::DoTopMargin(char *val)
{
   // Set top text margin.

   fButton->SetTopMargin(atoi(val));
   gClient->NeedRedraw(fButton);
}

//______________________________________________________________________________
void ButtonWindow::DoBottomMargin(char *val)
{
   // Set bottom text margin.

   fButton->SetBottomMargin(atoi(val));
   gClient->NeedRedraw(fButton);
}


////////////////////////////////////////////////////////////////////////////////
void buttonTest()
{
   // Main program.

   new ButtonWindow();
}
 buttonTest.C:1
 buttonTest.C:2
 buttonTest.C:3
 buttonTest.C:4
 buttonTest.C:5
 buttonTest.C:6
 buttonTest.C:7
 buttonTest.C:8
 buttonTest.C:9
 buttonTest.C:10
 buttonTest.C:11
 buttonTest.C:12
 buttonTest.C:13
 buttonTest.C:14
 buttonTest.C:15
 buttonTest.C:16
 buttonTest.C:17
 buttonTest.C:18
 buttonTest.C:19
 buttonTest.C:20
 buttonTest.C:21
 buttonTest.C:22
 buttonTest.C:23
 buttonTest.C:24
 buttonTest.C:25
 buttonTest.C:26
 buttonTest.C:27
 buttonTest.C:28
 buttonTest.C:29
 buttonTest.C:30
 buttonTest.C:31
 buttonTest.C:32
 buttonTest.C:33
 buttonTest.C:34
 buttonTest.C:35
 buttonTest.C:36
 buttonTest.C:37
 buttonTest.C:38
 buttonTest.C:39
 buttonTest.C:40
 buttonTest.C:41
 buttonTest.C:42
 buttonTest.C:43
 buttonTest.C:44
 buttonTest.C:45
 buttonTest.C:46
 buttonTest.C:47
 buttonTest.C:48
 buttonTest.C:49
 buttonTest.C:50
 buttonTest.C:51
 buttonTest.C:52
 buttonTest.C:53
 buttonTest.C:54
 buttonTest.C:55
 buttonTest.C:56
 buttonTest.C:57
 buttonTest.C:58
 buttonTest.C:59
 buttonTest.C:60
 buttonTest.C:61
 buttonTest.C:62
 buttonTest.C:63
 buttonTest.C:64
 buttonTest.C:65
 buttonTest.C:66
 buttonTest.C:67
 buttonTest.C:68
 buttonTest.C:69
 buttonTest.C:70
 buttonTest.C:71
 buttonTest.C:72
 buttonTest.C:73
 buttonTest.C:74
 buttonTest.C:75
 buttonTest.C:76
 buttonTest.C:77
 buttonTest.C:78
 buttonTest.C:79
 buttonTest.C:80
 buttonTest.C:81
 buttonTest.C:82
 buttonTest.C:83
 buttonTest.C:84
 buttonTest.C:85
 buttonTest.C:86
 buttonTest.C:87
 buttonTest.C:88
 buttonTest.C:89
 buttonTest.C:90
 buttonTest.C:91
 buttonTest.C:92
 buttonTest.C:93
 buttonTest.C:94
 buttonTest.C:95
 buttonTest.C:96
 buttonTest.C:97
 buttonTest.C:98
 buttonTest.C:99
 buttonTest.C:100
 buttonTest.C:101
 buttonTest.C:102
 buttonTest.C:103
 buttonTest.C:104
 buttonTest.C:105
 buttonTest.C:106
 buttonTest.C:107
 buttonTest.C:108
 buttonTest.C:109
 buttonTest.C:110
 buttonTest.C:111
 buttonTest.C:112
 buttonTest.C:113
 buttonTest.C:114
 buttonTest.C:115
 buttonTest.C:116
 buttonTest.C:117
 buttonTest.C:118
 buttonTest.C:119
 buttonTest.C:120
 buttonTest.C:121
 buttonTest.C:122
 buttonTest.C:123
 buttonTest.C:124
 buttonTest.C:125
 buttonTest.C:126
 buttonTest.C:127
 buttonTest.C:128
 buttonTest.C:129
 buttonTest.C:130
 buttonTest.C:131
 buttonTest.C:132
 buttonTest.C:133
 buttonTest.C:134
 buttonTest.C:135
 buttonTest.C:136
 buttonTest.C:137
 buttonTest.C:138
 buttonTest.C:139
 buttonTest.C:140
 buttonTest.C:141
 buttonTest.C:142
 buttonTest.C:143
 buttonTest.C:144
 buttonTest.C:145
 buttonTest.C:146
 buttonTest.C:147
 buttonTest.C:148
 buttonTest.C:149
 buttonTest.C:150
 buttonTest.C:151
 buttonTest.C:152
 buttonTest.C:153
 buttonTest.C:154
 buttonTest.C:155
 buttonTest.C:156
 buttonTest.C:157
 buttonTest.C:158
 buttonTest.C:159
 buttonTest.C:160
 buttonTest.C:161
 buttonTest.C:162
 buttonTest.C:163
 buttonTest.C:164
 buttonTest.C:165
 buttonTest.C:166
 buttonTest.C:167
 buttonTest.C:168
 buttonTest.C:169
 buttonTest.C:170
 buttonTest.C:171
 buttonTest.C:172
 buttonTest.C:173
 buttonTest.C:174
 buttonTest.C:175
 buttonTest.C:176
 buttonTest.C:177
 buttonTest.C:178
 buttonTest.C:179
 buttonTest.C:180
 buttonTest.C:181
 buttonTest.C:182
 buttonTest.C:183
 buttonTest.C:184
 buttonTest.C:185
 buttonTest.C:186
 buttonTest.C:187
 buttonTest.C:188
 buttonTest.C:189
 buttonTest.C:190
 buttonTest.C:191
 buttonTest.C:192
 buttonTest.C:193
 buttonTest.C:194
 buttonTest.C:195
 buttonTest.C:196
 buttonTest.C:197
 buttonTest.C:198
 buttonTest.C:199
 buttonTest.C:200
 buttonTest.C:201
 buttonTest.C:202
 buttonTest.C:203
 buttonTest.C:204
 buttonTest.C:205
 buttonTest.C:206
 buttonTest.C:207
 buttonTest.C:208
 buttonTest.C:209
 buttonTest.C:210
 buttonTest.C:211
 buttonTest.C:212
 buttonTest.C:213
 buttonTest.C:214
 buttonTest.C:215
 buttonTest.C:216
 buttonTest.C:217
 buttonTest.C:218
 buttonTest.C:219
 buttonTest.C:220
 buttonTest.C:221
 buttonTest.C:222
 buttonTest.C:223
 buttonTest.C:224
 buttonTest.C:225
 buttonTest.C:226
 buttonTest.C:227
 buttonTest.C:228
 buttonTest.C:229
 buttonTest.C:230
 buttonTest.C:231
 buttonTest.C:232