buttonTest.C

Go to the documentation of this file.
00001 // Author: Valeriy Onuchin   17/07/2007
00002 //
00003 // This macro gives an example of how to set/change text button attributes. 
00004 //
00005 // To run it do either:
00006 // .x buttonTest.C
00007 // .x buttonTest.C++
00008 
00009 #include <TGButton.h>
00010 #include <TGButtonGroup.h>
00011 #include <TGLabel.h>
00012 #include <TGNumberEntry.h>
00013 #include <TG3DLine.h>
00014 #include <TApplication.h>
00015 
00016 
00017 
00018 //////////// auxilary class ///////////////////////////////////////////////////
00019 class TextMargin : public TGHorizontalFrame {
00020 
00021 protected:
00022    TGNumberEntry *fEntry;
00023 
00024 public:
00025    TextMargin(const TGWindow *p, const char *name) : TGHorizontalFrame(p) 
00026    {
00027       fEntry = new TGNumberEntry(this, 0, 6, -1, TGNumberFormat::kNESInteger);
00028       AddFrame(fEntry, new TGLayoutHints(kLHintsLeft));
00029       TGLabel *label = new TGLabel(this, name);
00030       AddFrame(label, new TGLayoutHints(kLHintsLeft, 10));
00031    }
00032    TGTextEntry *GetEntry() const { return fEntry->GetNumberEntry(); }
00033 
00034    ClassDef(TextMargin, 0)
00035 };
00036 
00037 ////////////////////////////////////////////////////////////////////////////////
00038 class ButtonWindow : public TGMainFrame {
00039 
00040 protected:
00041    TGTextButton *fButton;   // button being tested
00042    
00043 public:
00044    ButtonWindow();
00045    void DoHPosition(Int_t);
00046    void DoVPosition(Int_t);
00047    void DoLeftMargin(char*);
00048    void DoRightMargin(char*);
00049    void DoTopMargin(char*);
00050    void DoBottomMargin(char*);
00051    
00052    ClassDef(ButtonWindow, 0)
00053 };
00054 
00055 
00056 //______________________________________________________________________________
00057 ButtonWindow::ButtonWindow() : TGMainFrame(gClient->GetRoot(), 10, 10, kHorizontalFrame)
00058 {
00059    // Main test window.
00060 
00061    SetCleanup(kDeepCleanup);
00062 
00063    // Controls on right
00064    TGVerticalFrame *controls = new TGVerticalFrame(this);
00065    AddFrame(controls, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 
00066                                         5, 5, 5, 5));
00067 
00068    // Separator
00069    TGVertical3DLine *separator = new TGVertical3DLine(this);
00070    AddFrame(separator, new TGLayoutHints(kLHintsRight | kLHintsExpandY));
00071 
00072    // Contents
00073    TGHorizontalFrame *contents = new TGHorizontalFrame(this);
00074    AddFrame(contents, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5));
00075 
00076    // The button for test
00077    fButton = new TGTextButton(contents,
00078       "&This button has a multi-line label\nand shows features\n"
00079       "available in the button classes");
00080    fButton->Resize(300, 200);
00081    fButton->ChangeOptions(fButton->GetOptions() | kFixedSize);
00082    fButton->SetToolTipText("The assigned tooltip\ncan be multi-line also",200);
00083    contents->AddFrame(fButton, new TGLayoutHints(kLHintsCenterX|kLHintsCenterY,
00084                       20, 20, 20, 20));
00085 
00086    TGGroupFrame *group = new TGGroupFrame(controls, "Enable/Disable");
00087    group->SetTitlePos(TGGroupFrame::kCenter);
00088    TGCheckButton *disable = new TGCheckButton(group, "Switch state\nEnable/Disable");
00089    disable->SetOn();
00090    disable->Connect("Toggled(Bool_t)", "TGButton", fButton, "SetEnabled(Bool_t)");
00091    group->AddFrame(disable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00092    controls->AddFrame(group, new TGLayoutHints(kLHintsExpandX));
00093 
00094 
00095    // control horizontal position of the text
00096    TGButtonGroup *horizontal = new TGButtonGroup(controls, "Horizontal Position");
00097    horizontal->SetTitlePos(TGGroupFrame::kCenter);
00098    new TGRadioButton(horizontal, "Center", kTextCenterX);
00099    new TGRadioButton(horizontal, "Left", kTextLeft);
00100    new TGRadioButton(horizontal, "Right", kTextRight);
00101    horizontal->SetButton(kTextCenterX);
00102    horizontal->Connect("Pressed(Int_t)", "ButtonWindow", this, 
00103                        "DoHPosition(Int_t)");
00104    controls->AddFrame(horizontal, new TGLayoutHints(kLHintsExpandX));
00105 
00106 
00107    // control vertical position of the text
00108    TGButtonGroup *vertical = new TGButtonGroup(controls, "Vertical Position");
00109    vertical->SetTitlePos(TGGroupFrame::kCenter);
00110    new TGRadioButton(vertical, "Center", kTextCenterY);
00111    new TGRadioButton(vertical, "Top", kTextTop);
00112    new TGRadioButton(vertical, "Bottom", kTextBottom);
00113    vertical->SetButton(kTextCenterY);
00114    vertical->Connect("Pressed(Int_t)", "ButtonWindow", this, 
00115                      "DoVPosition(Int_t)");
00116    controls->AddFrame(vertical, new TGLayoutHints(kLHintsExpandX));
00117 
00118 
00119    // control margins of the text
00120    TGGroupFrame *margins = new TGGroupFrame(controls, "Text Margins");
00121    margins->SetTitlePos(TGGroupFrame::kCenter);
00122 
00123    TextMargin *left = new TextMargin(margins, "Left");
00124    margins->AddFrame(left, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
00125    left->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
00126                              this, "DoLeftMargin(char*)");
00127 
00128    TextMargin *right = new TextMargin(margins, "Right");
00129    margins->AddFrame(right, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
00130    right->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
00131                                this, "DoRightMargin(char*)");
00132 
00133    TextMargin *top = new TextMargin(margins, "Top");
00134    margins->AddFrame(top, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
00135    top->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
00136                              this, "DoTopMargin(char*)");
00137 
00138    TextMargin *bottom = new TextMargin(margins, "Bottom");
00139    margins->AddFrame(bottom, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
00140    bottom->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
00141                                this, "DoBottomMargin(char*)");
00142 
00143    controls->AddFrame(margins, new TGLayoutHints(kLHintsExpandX));
00144 
00145    TGTextButton *quit = new TGTextButton(controls, "Quit");
00146    controls->AddFrame(quit, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
00147                                               0, 0, 0, 5));
00148    quit->Connect("Pressed()", "TApplication", gApplication, "Terminate()");
00149 
00150    Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
00151    DontCallClose();
00152 
00153    MapSubwindows();
00154    Resize();
00155 
00156    SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), 1000, 1000, 0 ,0);
00157    SetWindowName("Button Test");
00158    MapRaised();
00159 }
00160 
00161 //______________________________________________________________________________
00162 void ButtonWindow::DoHPosition(Int_t id)
00163 {
00164    // Horizontal position handler.
00165 
00166    Int_t tj = fButton->GetTextJustify();
00167    tj &= ~kTextCenterX;
00168    tj &= ~kTextLeft;
00169    tj &= ~kTextRight;
00170    tj |= id;
00171    fButton->SetTextJustify(tj);
00172 }
00173 
00174 //______________________________________________________________________________
00175 void ButtonWindow::DoVPosition(Int_t id)
00176 {
00177    // Vertical position handler.
00178 
00179    Int_t tj = fButton->GetTextJustify();
00180 
00181    tj &= ~kTextCenterY;
00182    tj &= ~kTextTop;
00183    tj &= ~kTextBottom;
00184    tj |= id;
00185    fButton->SetTextJustify(tj);
00186 }
00187 
00188 //______________________________________________________________________________
00189 void ButtonWindow::DoLeftMargin(char *val)
00190 {
00191    // Set left text margin.
00192 
00193    fButton->SetLeftMargin(atoi(val));
00194    gClient->NeedRedraw(fButton);
00195 }  
00196 
00197 //______________________________________________________________________________
00198 void ButtonWindow::DoRightMargin(char *val)
00199 {
00200    // Set right text margin.
00201 
00202    fButton->SetRightMargin(atoi(val));
00203    gClient->NeedRedraw(fButton);
00204 }
00205 
00206 //______________________________________________________________________________
00207 void ButtonWindow::DoTopMargin(char *val)
00208 {
00209    // Set top text margin.
00210 
00211    fButton->SetTopMargin(atoi(val));
00212    gClient->NeedRedraw(fButton);
00213 }
00214 
00215 //______________________________________________________________________________
00216 void ButtonWindow::DoBottomMargin(char *val)
00217 {
00218    // Set bottom text margin.
00219 
00220    fButton->SetBottomMargin(atoi(val));
00221    gClient->NeedRedraw(fButton);
00222 }
00223 
00224 
00225 ////////////////////////////////////////////////////////////////////////////////
00226 void buttonTest()
00227 {
00228    // Main program.
00229 
00230    new ButtonWindow();
00231 }

Generated on Tue Jul 5 15:44:23 2011 for ROOT_528-00b_version by  doxygen 1.5.1