Logo ROOT  
Reference Guide
buttonTest.C File Reference

Detailed Description

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);
TGLabel *label = new TGLabel(this, name);
}
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
// 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);
20, 20, 20, 20));
TGGroupFrame *group = new TGGroupFrame(controls, "Enable/Disable");
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));
// control horizontal position of the text
TGButtonGroup *horizontal = new TGButtonGroup(controls, "Horizontal Position");
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");
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");
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");
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();
}
Author
Valeriy Onuchin 17/07/2007

Definition in file buttonTest.C.

ROOT::TMetaUtils::propNames::separator
static const std::string separator("@@@")
TGButtonGroup::SetButton
virtual void SetButton(Int_t id, Bool_t down=kTRUE)
Sets the button with id to be on/down, and if this is an exclusive group, all other button in the gro...
Definition: TGButtonGroup.cxx:334
TGWindow
Definition: TGWindow.h:31
kLHintsCenterX
@ kLHintsCenterX
Definition: TGLayout.h:38
kTextTop
@ kTextTop
Definition: TGWidget.h:43
TGMainFrame
Definition: TGFrame.h:444
TGGroupFrame::SetTitlePos
virtual void SetTitlePos(ETitlePos pos=kLeft)
Definition: TGFrame.h:629
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TGLabel
Definition: TGLabel.h:32
TGTextButton
Definition: TGButton.h:142
Int_t
int Int_t
Definition: RtypesCore.h:45
kTextCenterX
@ kTextCenterX
Definition: TGWidget.h:42
TGVertical3DLine
Definition: TG3DLine.h:44
TGButtonGroup
Definition: TGButtonGroup.h:31
TGHorizontalFrame
Definition: TGFrame.h:423
kTextCenterY
@ kTextCenterY
Definition: TGWidget.h:45
TGNumberEntry::GetNumberEntry
TGNumberEntryField * GetNumberEntry() const
Definition: TGNumberEntry.h:268
id
XFontStruct * id
Definition: TGX11.cxx:109
gClient
#define gClient
Definition: TGClient.h:166
kTextLeft
@ kTextLeft
Definition: TGWidget.h:40
kLHintsBottom
@ kLHintsBottom
Definition: TGLayout.h:42
TApplication.h
TGCheckButton
Definition: TGButton.h:264
group
Definition: TWinNTSystem.h:59
TG3DLine.h
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:41
TGRadioButton
Definition: TGButton.h:322
TGVerticalFrame
Definition: TGFrame.h:412
TGTextEntry
Definition: TGTextEntry.h:39
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:39
TGLayoutHints
Definition: TGLayout.h:57
TGGroupFrame
Definition: TGFrame.h:587
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TGButtonGroup.h
kFixedSize
@ kFixedSize
Definition: GuiTypes.h:390
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:44
kTextBottom
@ kTextBottom
Definition: TGWidget.h:44
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGLabel.h
TQObject::Connect
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:864
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
name
char name[80]
Definition: TGX11.cxx:110
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:51
TGButton::SetOn
virtual void SetOn(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition: TGButton.h:120
TGGroupFrame::kCenter
@ kCenter
Definition: TGFrame.h:606
TGNumberEntry.h
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
kTextRight
@ kTextRight
Definition: TGWidget.h:41
TGNumberEntry
Definition: TGNumberEntry.h:156
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TGNumberFormat::kNESInteger
@ kNESInteger
Definition: TGNumberEntry.h:46