Logo ROOT   6.14/05
Reference Guide
textEntries.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// This macro gives an example of how to set/change text entry attributes.
4 /// To run it do either:
5 /// ~~~
6 /// .x textEntries.C
7 /// .x textEntries.C++
8 /// ~~~
9 ///
10 /// \macro_code
11 ///
12 /// \author Valeriy Onuchin 25/08/2007
13 
14 #include <TGTextEntry.h>
15 #include <TGButtonGroup.h>
16 #include <TGLabel.h>
17 #include <TGComboBox.h>
18 #include <TApplication.h>
19 
20 
21 //////////// auxilary class ///////////////////////////////////////////////////
22 class GroupBox : public TGGroupFrame {
23 private:
24  TGComboBox *fCombo; // combo box
25  TGTextEntry *fEntry; // text entry
26 
27 public:
28  GroupBox(const TGWindow *p, const char *name, const char *title);
29  TGTextEntry *GetEntry() const { return fEntry; }
30  TGComboBox *GetCombo() const { return fCombo; }
31 
32  ClassDef(GroupBox, 0)
33 };
34 
35 //______________________________________________________________________________
36 GroupBox::GroupBox(const TGWindow *p, const char *name, const char *title) :
37  TGGroupFrame(p, name)
38 {
39  // Group frame containing combobox and text entry.
40 
41  TGHorizontalFrame *horz = new TGHorizontalFrame(this);
42  AddFrame(horz, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
43  TGLabel *label = new TGLabel(horz, title);
44  horz->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
45 
46  fCombo = new TGComboBox(horz);
48  5, 0, 5, 5));
49  fCombo->Resize(100, 20);
50 
51  fEntry = new TGTextEntry(this);
52  AddFrame(fEntry, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 class TextEntryWindow {
57 
58 protected:
59  TGMainFrame *fMain; // main frame
60  GroupBox *fEcho; // echo mode (echo, password, no echo)
61  GroupBox *fAlign; // alignment (left, right, center)
62  GroupBox *fAccess; // read-only mode
63  GroupBox *fBorder; // border mode
64 
65 public:
66  TextEntryWindow();
67  virtual ~TextEntryWindow() { delete fMain; }
68 
69  ClassDef(TextEntryWindow, 0);
70 };
71 
72 
73 //______________________________________________________________________________
74 TextEntryWindow::TextEntryWindow()
75 {
76  // Main test window.
77 
78  TGComboBox *combo;
79  TGTextEntry *entry;
80 
81  fMain = new TGMainFrame(gClient->GetRoot(), 10, 10, kVerticalFrame);
82 
83  // recusively delete all subframes on exit
84  fMain->SetCleanup(kDeepCleanup);
85 
86  fEcho = new GroupBox(fMain, "Echo", "Mode:");
87  fMain->AddFrame(fEcho, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
88  combo = fEcho->GetCombo();
89  entry = fEcho->GetEntry();
90  // add entries
91  combo->AddEntry("Normal", TGTextEntry::kNormal);
92  combo->AddEntry("Password", TGTextEntry::kPassword);
93  combo->AddEntry("No Echo", TGTextEntry::kNoEcho);
94  combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetEchoMode(TGTextEntry::EEchoMode)");
96 
97  fAlign = new GroupBox(fMain, "Alignment", "Type:");
98  fMain->AddFrame(fAlign, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
99  combo = fAlign->GetCombo();
100  entry = fAlign->GetEntry();
101  // add entries
102  combo->AddEntry("Left", kTextLeft);
103  combo->AddEntry("Centered", kTextCenterX);
104  combo->AddEntry("Right", kTextRight);
105  combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetAlignment(ETextJustification)");
106  combo->Select(kTextLeft);
107 
108  fAccess = new GroupBox(fMain, "Access", "Read-only:");
109  fMain->AddFrame(fAccess, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
110  combo = fAccess->GetCombo();
111  entry = fAccess->GetEntry();
112  // add entries
113  combo->AddEntry("False", 1);
114  combo->AddEntry("True", 0);
115  combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetEnabled(Int_t)");
116  combo->Select(1);
117 
118  fBorder = new GroupBox(fMain, "Border", "Drawn:");
119  fMain->AddFrame(fBorder, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
120  combo = fBorder->GetCombo();
121  entry = fBorder->GetEntry();
122  // add entries
123  combo->AddEntry("False", 0);
124  combo->AddEntry("True", 1);
125  combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetFrameDrawn(Int_t)");
126  combo->Select(1);
127 
128  // terminate ROOT session when window is closed
129  fMain->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
130  fMain->DontCallClose();
131 
132  fMain->MapSubwindows();
133  fMain->Resize();
134 
135  // set minimum width, height
136  fMain->SetWMSizeHints(fMain->GetDefaultWidth(), fMain->GetDefaultHeight(),
137  1000, 1000, 0, 0);
138  fMain->SetWindowName("Text Entries");
139  fMain->MapRaised();
140 }
141 
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 void textEntries()
145 {
146  // Main program.
147 
148  new TextEntryWindow();
149 }
#define gClient
Definition: TGClient.h:166
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
Definition: TGComboBox.cxx:443
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:867
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:106
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
char name[80]
Definition: TGX11.cxx:109