Logo ROOT  
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 }
TGTextEntry::kNoEcho
@ kNoEcho
Definition: TGTextEntry.h:42
TGComboBox.h
TGWindow
Definition: TGWindow.h:31
TGMainFrame
Definition: TGFrame.h:443
TGComboBox::AddEntry
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:106
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:31
TGLabel
Definition: TGLabel.h:32
TGComboBox::Select
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:451
kTextCenterX
@ kTextCenterX
Definition: TGWidget.h:35
TGHorizontalFrame
Definition: TGFrame.h:422
gClient
#define gClient
Definition: TGClient.h:166
kTextLeft
@ kTextLeft
Definition: TGWidget.h:33
TApplication.h
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:35
TGTextEntry
Definition: TGTextEntry.h:39
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:33
TGLayoutHints
Definition: TGLayout.h:57
TGTextEntry::kPassword
@ kPassword
Definition: TGTextEntry.h:42
TGGroupFrame
Definition: TGFrame.h:586
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TGButtonGroup.h
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:38
TGTextEntry::kNormal
@ kNormal
Definition: TGTextEntry.h:42
TGComboBox
Definition: TGComboBox.h:67
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:866
TGTextEntry.h
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:50
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:37
kTextRight
@ kTextRight
Definition: TGWidget.h:34
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