#include <TGButton.h>
#include <TGButtonGroup.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TG3DLine.h>
#include <TApplication.h>
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;
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)
{
SetCleanup(kDeepCleanup);
TGVerticalFrame *controls = new TGVerticalFrame(this);
AddFrame(controls, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 5, 5, 5, 5));
TGVertical3DLine *separator = new TGVertical3DLine(this);
AddFrame(separator, new TGLayoutHints(kLHintsRight | kLHintsExpandY));
TGHorizontalFrame *contents = new TGHorizontalFrame(this);
AddFrame(contents, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5));
fButton = new TGTextButton(contents,
"&This button has a multi-line label\nand shows features\navailable 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));
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));
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));
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)
{
Int_t tj = fButton->GetTextJustify();
tj &= ~kTextCenterX;
tj &= ~kTextLeft;
tj &= ~kTextRight;
tj |= id;
fButton->SetTextJustify(tj);
}
void ButtonWindow::DoVPosition(Int_t id)
{
Int_t tj = fButton->GetTextJustify();
tj &= ~kTextCenterY;
tj &= ~kTextTop;
tj &= ~kTextBottom;
tj |= id;
fButton->SetTextJustify(tj);
}
void ButtonWindow::DoLeftMargin(char *val)
{
fButton->SetLeftMargin(atoi(val));
gClient->NeedRedraw(fButton);
}
void ButtonWindow::DoRightMargin(char *val)
{
fButton->SetRightMargin(atoi(val));
gClient->NeedRedraw(fButton);
}
void ButtonWindow::DoTopMargin(char *val)
{
fButton->SetTopMargin(atoi(val));
gClient->NeedRedraw(fButton);
}
void ButtonWindow::DoBottomMargin(char *val)
{
fButton->SetBottomMargin(atoi(val));
gClient->NeedRedraw(fButton);
}
void buttonTest()
{
new ButtonWindow();
}
|
|