textEntries.C

Go to the documentation of this file.
00001 // Author: Valeriy Onuchin   25/08/2007
00002 //
00003 // This macro gives an example of how to set/change text entry attributes. 
00004 //
00005 // To run it do either:
00006 // .x textEntries.C
00007 // .x textEntries.C++
00008 
00009 #include <TGTextEntry.h>
00010 #include <TGButtonGroup.h>
00011 #include <TGLabel.h>
00012 #include <TGComboBox.h>
00013 #include <TApplication.h>
00014 
00015 
00016 //////////// auxilary class ///////////////////////////////////////////////////
00017 class GroupBox : public TGGroupFrame {
00018 private:
00019    TGComboBox  *fCombo; // combo box
00020    TGTextEntry *fEntry; // text entry 
00021 
00022 public:
00023    GroupBox(const TGWindow *p, const char *name, const char *title);
00024    TGTextEntry *GetEntry() const { return fEntry; }
00025    TGComboBox  *GetCombo() const { return fCombo; }
00026 
00027    ClassDef(GroupBox, 0)
00028 };
00029 
00030 //______________________________________________________________________________
00031 GroupBox::GroupBox(const TGWindow *p, const char *name, const char *title) :
00032    TGGroupFrame(p, name) 
00033 {
00034    // Group frame containing combobox and text entry.
00035 
00036    TGHorizontalFrame *horz = new TGHorizontalFrame(this);
00037    AddFrame(horz, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
00038    TGLabel *label = new TGLabel(horz, title);
00039    horz->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
00040 
00041    fCombo = new TGComboBox(horz);
00042    horz->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsExpandY,
00043                                             5, 0, 5, 5));
00044    fCombo->Resize(100, 20);
00045 
00046    fEntry = new TGTextEntry(this);
00047    AddFrame(fEntry, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
00048 }
00049 
00050 ////////////////////////////////////////////////////////////////////////////////
00051 class TextEntryWindow {
00052 
00053 protected:
00054    TGMainFrame *fMain;     // main frame
00055    GroupBox    *fEcho;     // echo mode (echo, password, no echo)
00056    GroupBox    *fAlign;    // alignment (left, right, center)
00057    GroupBox    *fAccess;   // read-only mode
00058    GroupBox    *fBorder;   // border mode
00059 
00060 public:
00061    TextEntryWindow();
00062    virtual ~TextEntryWindow() { delete fMain; }
00063    
00064    ClassDef(TextEntryWindow, 0);
00065 };
00066 
00067 
00068 //______________________________________________________________________________
00069 TextEntryWindow::TextEntryWindow()
00070 {
00071    // Main test window.
00072 
00073    TGComboBox  *combo;
00074    TGTextEntry *entry; 
00075 
00076    fMain = new TGMainFrame(gClient->GetRoot(), 10, 10, kVerticalFrame);
00077 
00078    // recusively delete all subframes on exit
00079    fMain->SetCleanup(kDeepCleanup);
00080 
00081    fEcho = new GroupBox(fMain, "Echo", "Mode:");
00082    fMain->AddFrame(fEcho, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
00083    combo = fEcho->GetCombo();
00084    entry = fEcho->GetEntry();
00085    // add entries
00086    combo->AddEntry("Normal", TGTextEntry::kNormal);
00087    combo->AddEntry("Password", TGTextEntry::kPassword);
00088    combo->AddEntry("No Echo", TGTextEntry::kNoEcho);
00089    combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetEchoMode(Int_t)");
00090    combo->Select(TGTextEntry::kNormal);
00091 
00092    fAlign = new GroupBox(fMain, "Alignment", "Type:");
00093    fMain->AddFrame(fAlign, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
00094    combo = fAlign->GetCombo();
00095    entry = fAlign->GetEntry();
00096    // add entries
00097    combo->AddEntry("Left", kTextLeft);
00098    combo->AddEntry("Centered", kTextCenterX);
00099    combo->AddEntry("Right", kTextRight);
00100    combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetAlignment(Int_t)");
00101    combo->Select(kTextLeft);
00102 
00103    fAccess = new GroupBox(fMain, "Access", "Read-only:");
00104    fMain->AddFrame(fAccess, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
00105    combo = fAccess->GetCombo();
00106    entry = fAccess->GetEntry();
00107    // add entries
00108    combo->AddEntry("False", 1);
00109    combo->AddEntry("True", 0);
00110    combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetEnabled(Int_t)");
00111    combo->Select(1);
00112 
00113    fBorder = new GroupBox(fMain, "Border", "Drawn:");
00114    fMain->AddFrame(fBorder, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
00115    combo = fBorder->GetCombo();
00116    entry = fBorder->GetEntry();
00117    // add entries
00118    combo->AddEntry("False", 0);
00119    combo->AddEntry("True", 1);
00120    combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetFrameDrawn(Int_t)");
00121    combo->Select(1);
00122 
00123    // terminate ROOT session when window is closed
00124    fMain->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
00125    fMain->DontCallClose();
00126 
00127    fMain->MapSubwindows();
00128    fMain->Resize();
00129 
00130    // set minimum width, height
00131    fMain->SetWMSizeHints(fMain->GetDefaultWidth(), fMain->GetDefaultHeight(),
00132                          1000, 1000, 0, 0);
00133    fMain->SetWindowName("Text Entries");
00134    fMain->MapRaised();
00135 }
00136 
00137 
00138 ////////////////////////////////////////////////////////////////////////////////
00139 void textEntries()
00140 {
00141    // Main program.
00142 
00143    new TextEntryWindow();
00144 }

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