Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
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//////////// auxilary class ///////////////////////////////////////////////////
21class GroupBox : public TGGroupFrame {
22private:
23 TGComboBox *fCombo; // combo box
24 TGTextEntry *fEntry; // text entry
25
26public:
27 GroupBox(const TGWindow *p, const char *name, const char *title);
28 TGTextEntry *GetEntry() const { return fEntry; }
29 TGComboBox *GetCombo() const { return fCombo; }
30
32};
33
34//______________________________________________________________________________
35GroupBox::GroupBox(const TGWindow *p, const char *name, const char *title) : TGGroupFrame(p, name)
36{
37 // Group frame containing combobox and text entry.
38
41 TGLabel *label = new TGLabel(horz, title);
42 horz->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
43
44 fCombo = new TGComboBox(horz);
45 horz->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 5, 0, 5, 5));
46 fCombo->Resize(100, 20);
47
48 fEntry = new TGTextEntry(this);
49 AddFrame(fEntry, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
50}
51
52////////////////////////////////////////////////////////////////////////////////
53class TextEntryWindow {
54
55protected:
56 TGMainFrame *fMain; // main frame
57 GroupBox *fEcho; // echo mode (echo, password, no echo)
58 GroupBox *fAlign; // alignment (left, right, center)
59 GroupBox *fAccess; // read-only mode
60 GroupBox *fBorder; // border mode
61
62public:
64 virtual ~TextEntryWindow() { delete fMain; }
65
67};
68
69//______________________________________________________________________________
70TextEntryWindow::TextEntryWindow()
71{
72 // Main test window.
73
76
77 fMain = new TGMainFrame(gClient->GetRoot(), 10, 10, kVerticalFrame);
78
79 // recusively delete all subframes on exit
80 fMain->SetCleanup(kDeepCleanup);
81
82 fEcho = new GroupBox(fMain, "Echo", "Mode:");
83 fMain->AddFrame(fEcho, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
84 combo = fEcho->GetCombo();
85 entry = fEcho->GetEntry();
86 // add entries
87 combo->AddEntry("Normal", TGTextEntry::kNormal);
88 combo->AddEntry("Password", TGTextEntry::kPassword);
89 combo->AddEntry("No Echo", TGTextEntry::kNoEcho);
90 combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetEchoMode(TGTextEntry::EEchoMode)");
92
93 fAlign = new GroupBox(fMain, "Alignment", "Type:");
94 fMain->AddFrame(fAlign, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
95 combo = fAlign->GetCombo();
96 entry = fAlign->GetEntry();
97 // add entries
98 combo->AddEntry("Left", kTextLeft);
99 combo->AddEntry("Centered", kTextCenterX);
100 combo->AddEntry("Right", kTextRight);
101 combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetAlignment(ETextJustification)");
102 combo->Select(kTextLeft);
103
104 fAccess = new GroupBox(fMain, "Access", "Read-only:");
105 fMain->AddFrame(fAccess, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
106 combo = fAccess->GetCombo();
107 entry = fAccess->GetEntry();
108 // add entries
109 combo->AddEntry("False", 1);
110 combo->AddEntry("True", 0);
111 combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetEnabled(Int_t)");
112 combo->Select(1);
113
114 fBorder = new GroupBox(fMain, "Border", "Drawn:");
115 fMain->AddFrame(fBorder, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
116 combo = fBorder->GetCombo();
117 entry = fBorder->GetEntry();
118 // add entries
119 combo->AddEntry("False", 0);
120 combo->AddEntry("True", 1);
121 combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetFrameDrawn(Int_t)");
122 combo->Select(1);
123
124 // terminate ROOT session when window is closed
125 fMain->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
126 fMain->DontCallClose();
127
128 fMain->MapSubwindows();
129 fMain->Resize();
130
131 // set minimum width, height
132 fMain->SetWMSizeHints(fMain->GetDefaultWidth(), fMain->GetDefaultHeight(), 1000, 1000, 0, 0);
133 fMain->SetWindowName("Text Entries");
134 fMain->MapRaised();
135}
136
137////////////////////////////////////////////////////////////////////////////////
138void textEntries()
139{
140 // Main program.
141
142 new TextEntryWindow();
143}
@ kVerticalFrame
Definition GuiTypes.h:381
#define ClassDef(name, id)
Definition Rtypes.h:342
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gClient
Definition TGClient.h:157
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsExpandX
Definition TGLayout.h:30
@ kTextCenterX
Definition TGWidget.h:25
@ kTextLeft
Definition TGWidget.h:23
@ kTextRight
Definition TGWidget.h:24
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition TGX11.cxx:110
A combobox (also known as a drop down listbox) allows the selection of one item out of a list of item...
Definition TGComboBox.h:47
A composite frame with a border and a title.
Definition TGFrame.h:524
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:399
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
ROOT GUI Window base class.
Definition TGWindow.h:23